栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Define aspect ratio when using twinx

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Define aspect ratio when using twinx

Have a look at the

adjustable
parameter of the axes. This controls whether
the data limits or the bounding rectangle’s shape are changed when the
aspect/limits are changed.

Normally, the options are

"box"
and
"datalim"
, but there’s a special case
for shared axes. In your case, you want
adjustable='box-forced'
.

As a quick example (I took the liberty of simplifying things slightly, feel
free to use the separate

set_foo
methods if they’re clearer to you. If you
take that route, the method is
ax.set_adjustable
.):

import numpy as npimport matplotlib.pyplot as pltx = np.linspace(0,1.6,50) + 50.0fig, ax = plt.subplots()ax2 = ax.twinx()XLIM = [50.0, 51.6]YLIM = [0.0, 1.1, 0.0, 11.0]ax.plot(x,np.sin(x-50.0),'b')ax2.plot(x,np.cos(x-50.0)*10.,'r')ax.set(adjustable='box-forced',       xlim=XLIM, ylim=YLIM[:2],       xticks=np.arange(XLIM[0], XLIM[1], 0.2),       yticks=np.arange(YLIM[0], YLIM[1]+0.1, 0.1)[:-1],       aspect=(XLIM[1]-XLIM[0])/(YLIM[1]-YLIM[0]))ax2.set(adjustable='box-forced',        ylim=YLIM[2:],        yticks=np.arange(YLIM[2], YLIM[3]+1.0, 1.0),        aspect=(XLIM[1]-XLIM[0])/(YLIM[3]-YLIM[2]))ax.grid(True, which='major',linestyle='solid')plt.show()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/611413.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号