shared_axis_demo.py

来自「非原创。很好的python例子」· Python 代码 · 共 53 行

PY
53
字号
"""You can share the x or y axis limits for one axis with another bypassing an axes instance as a sharex or sharey kwarg.Changing the axis limits on one axes will be reflected automaticallyin the other, and vice-versa, so when you navigate with the toolbarthe axes will follow each other on their shared axes.  Ditto forchanges in the axis scaling (eg log vs linear).  However, it ispossible to have differences in tick labeling, eg you can selectivelyturn off the tick labels on one axes.The example below shows how to customize the tick labels on thevarious axes.  Shared axes share the tick locator, tick formatter,view limits, and transformation (eg log, linear).  But the ticklabelsthemselves do not share properties.  This is a feature and not a bug,because you may want to make the tick labels smaller on the upperaxes, eg in the example below.If you want to turn off the ticklabels for a given axes (eg onsubplot(211) or subplot(212), you cannot do the standard trick   setp(ax2, xticklabels=[])because this changes the tick Formatter, which is shared among allaxes.  But you can alter the visibility of the labels, which is aproperty  setp( ax2.get_xticklabels(), visible=False)"""from pylab import *t = arange(0.01, 5.0, 0.01)s1 = sin(2*pi*t)s2 = exp(-t)s3 = sin(4*pi*t)ax1 = subplot(311)plot(t,s1)setp( ax1.get_xticklabels(), fontsize=6)## share x onlyax2 = subplot(312, sharex=ax1)plot(t, s2)# make these tick labels invisiblesetp( ax2.get_xticklabels(), visible=False)# share x and yax3 = subplot(313,  sharex=ax1, sharey=ax1)plot(t, s3)xlim(0.01,5.0)show()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?