Matplotlib:设置xticklabels返回了一些“帮助”输出

3
我有十二个箱线图,它们在同一个图中水平排列。我想让它们之间的距离保持一致,因此在调用plt.boxplot()时没有设置positions
对于每个箱线图,我希望相应的X轴标签拥有特定的值。 我这样做:
xtickNames = plt.setp(ax, xticklabels=[str(v) for v in values])
plt.setp(xtickNames)

它可以工作,但是我在屏幕上看到了所有的输出信息:

agg_filter: 未知 alpha: 浮点数 (0.0 表示完全透明,1.0表示不透明) animated: [True | False] axes: ~matplotlib.axes.Axes 实例 backgroundcolor: 任何 matplotlib 颜色 bbox: 矩形属性字典
clip_box: 一个 matplotlib.transforms.Bbox 实例
clip_on: [True | False] clip_path: [ (~matplotlib.path.Path,
~matplotlib.transforms.Transform) |
~matplotlib.patches.Patch | None ] color: 任意 matplotlib 颜色 contains: 可调用函数
family 或 fontfamily 或 fontname 或 name: [FONTNAME | 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' ] figure: 一个 matplotlib.figure.Figure 实例
fontproperties 或 font_properties: 一个 matplotlib.font_manager.FontProperties 实例
gid: 一个 id 字符串 horizontalalignment 或 ha: [ 'center' | 'right' | 'left' ] label: 字符串或可使用 '%s' 转换的任何内容。 linespacing: 浮点数(字体大小的倍数) lod: [True | False] multialignment: ['left' | 'right' | 'center' ] path_effects: 未知 picker: [None|float|boolean|callable] position: (x,y)
rasterized: [True | False | None] rotation: [ 角度值 | 'vertical' | 'horizontal' ] rotation_mode: 未知 size 或 fontsize: [点数大小 | 'xx-small' | 'x-small' | 'small' | 'medium' | 'large' | 'x-large' | 'xx-large' ] sketch_params: 未知 snap: 未知
stretch 或 fontstretch: [0-1000 范围内的数字 | 'ultra-condensed' | 'extra-condensed' | 'condensed' | 'semi-condensed' | 'normal' | 'semi-expanded' | 'expanded' | 'extra-expanded' | 'ultra-expanded' ]
style 或 fontstyle: [ 'normal' | 'italic' | 'oblique']
text: 字符串或可使用 '%s' 转换的任何内容。
transform: ~matplotlib.transforms.Transform 实例
url: 一个 URL 字符串 variant 或 fontvariant: [ 'normal' | 'small-caps' ] verticalalignment 或 va 或 ma: [ 'center' | 'top' | 'bottom' | 'baseline' ] visible: [True | False]
weight 或 fontweight: [0-1000 范围内的数字 | 'ultralight' | 'light' | 'normal' | 'regular' | 'book' | 'medium' | 'roman' | 'semibold' | 'demibold' | 'demi' | 'bold' | 'heavy' | 'extra bold' | 'black' ]
x: 浮点数 y: 浮点数 zorder: 任意数字

发生了什么问题?
1个回答

2
xtickNames = plt.setp(ax, xticklabels=[str(v) for v in values])

设置xticklabels属性。

plt.setp(xtickNames)

xtickNames的可配置属性打印到屏幕上。

因此,只需使用第一个命令设置xticklabels而不打印到屏幕上。或者,您可以使用下面的命令:

ax.set_xticklabels(map(str, values))

那么我甚至不需要将第一行的输出保存到变量中,对吧? - Ricky Robinson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接