tick_labels_from_values
从值列表中设置刻度标签使用ax.set_xticks会导致在当前选择的刻度上设置刻度标签。 但是,您可能希望允许matplotlib动态选择刻度数及其间距。 在这种情况下,最好从刻度线上的值确定刻度标签。 以下示例显示了如何执行此操作。 注意:这里使用MaxNLocator来确保刻度值取整数值。 12345678910111213141516171819import matplotlib.pyplot as pltfrom matplotlib.ticker import FuncFormatter, MaxNLocatorfig, ax = plt.subplots()xs = range(26)ys = range(26)labels = list('abcdefghijklmnopqrstuvwxyz')def format_fn(tick_val, tick_pos): if int(tick_val) in xs: return labels[int(tick_val)] else: return '...
tick_formatters
刻度格式化程序显示不同的刻度格式化程序。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100import numpy as npimport matplotlib.pyplot as pltimport matplotlib.ticker as ticker# Setup a plot such that only the bottom spine is showndef setup(ax): ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') ax.yaxis...
tick_label_right
在右侧设置默认的y轴刻度标签我们可以使用rcParams[“ytick.labelright”](默认为False)和rcParams[“ytick.right”](默认为False)和rcParams[“ytick.labelleft”](默认为True)和 rcParams[“ytick.left”](默认为True)控制轴上的刻度和标签出现的位置。这些属性也可以在.matplotlib / matplotlibrc中设置。 1234567891011121314151617import matplotlib.pyplot as pltimport numpy as npplt.rcParams['ytick.right'] = plt.rcParams['ytick.labelright'] = Trueplt.rcParams['ytick.left'] = plt.rcParams['ytick.labelleft'] = Falsex = np.arange(10)fig, (...
tick_locators
刻度定位器显示不同的刻度定位器。 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293import numpy as npimport matplotlib.pyplot as pltimport matplotlib.ticker as ticker# Setup a plot such that only the bottom spine is showndef setup(ax): ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') ax.yaxis.set_major_locator(...
ticklabels_rotation
旋转自定义刻度标签使用用户定义的旋转演示自定义刻度标签。 123456789101112131415import matplotlib.pyplot as pltx = [1, 2, 3, 4]y = [1, 4, 9, 6]labels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']plt.plot(x, y, 'ro')# You can specify a rotation for the tick labels in degrees or with keywords.plt.xticks(x, labels, rotation='vertical')# Pad margins so that markers don't get clipped by the axesplt.margins(0.2)# Tweak spacing to prevent clipping of tick-labelsplt.subplot...
tick_xlabel_top
在顶部设置默认的x轴刻度标签我们可以使用 rcParams[“xtick.labeltop”](默认为False)和rcParams[“xtick.top”](默认为False)和rcParams[“xtick.labelbottom”](默认为True)和 rcParams[“xtick.bottom”] (默认为True)控制轴上的刻度和标签出现的位置。 这些属性也可以在.matplotlib / matplotlibrc中设置。 123456789101112131415import matplotlib.pyplot as pltimport numpy as npplt.rcParams['xtick.bottom'] = plt.rcParams['xtick.labelbottom'] = Falseplt.rcParams['xtick.top'] = plt.rcParams['xtick.labeltop'] = Truex = np.arange(10)fig, ax...
artist_tests
艺术家对象测试每个Matplotlib原始艺术家类型的测试单元支持。 轴处理单位转换,艺术家保留指向其父轴的指针。如果要将它们与单位数据一起使用,则必须使用轴实例初始化艺术家,否则他们将不知道如何将单位转换为标量。 此示例需要 basic_units.py 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import randomimport matplotlib.lines as linesimport matplotlib.patches as patchesimport matplotlib.text as textimport matplotlib.collections as collectionsfrom basic_units import cm, inchimport numpy as npimport matplotlib.pyplot as pltfig, ax = plt.subplots()ax.xaxis.set_units...
annotate_with_units
带有单位的注释该示例说明了如何使用厘米级绘图创建文本和箭头注释。 此示例需要 basic_units.py 1234567891011121314151617181920212223import matplotlib.pyplot as pltfrom basic_units import cmfig, ax = plt.subplots()ax.annotate("Note 01", [0.5*cm, 0.5*cm])# xy and text both unitizedax.annotate('local max', xy=(3*cm, 1*cm), xycoords='data', xytext=(0.8*cm, 0.95*cm), textcoords='data', arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment=&...
bar_demo2
单位条形图使用各种厘米和英寸转换的图像。此示例显示默认单位内省如何工作(ax1),如何使用各种关键字来设置x和y单位以覆盖默认值(ax2,ax3,ax4)以及如何使用标量设置xlimits(ax3,当前单位) 假设)或单位(用于将数字转换为当前单位的转换)。 此示例需要 basic_units.py 12345678910111213141516171819202122import numpy as npfrom basic_units import cm, inchimport matplotlib.pyplot as pltcms = cm * np.arange(0, 10, 2)bottom = 0 * cmwidth = 0.8 * cmfig, axs = plt.subplots(2, 2)axs[0, 0].bar(cms, cms, bottom=bottom)axs[0, 1].bar(cms, cms, bottom=bottom, width=width, xunits=cm, yunits=inch)axs[1, 0].bar(cms, cms, bo...
bar_unit_demo
与单位组合的条形图此示例与以厘米为单位的条形图演示相同。 此示例需要 basic_units.py 123456789101112131415161718192021222324252627282930import numpy as npfrom basic_units import cm, inchimport matplotlib.pyplot as pltN = 5menMeans = (150*cm, 160*cm, 146*cm, 172*cm, 155*cm)menStd = (20*cm, 30*cm, 32*cm, 10*cm, 20*cm)fig, ax = plt.subplots()ind = np.arange(N) # the x locations for the groupswidth = 0.35 # the width of the barsp1 = ax.bar(ind, menMeans, width, color='r', bottom=0*cm, yerr=menStd)womenMeans =...














