我在同一个地 block 上有十几个箱线图,水平排列。我希望它们之间的间距保持不变,因此在调用 plt.boxplot()
时没有设置 positions
。
对于每个箱线图,我希望X轴上相应的标签具有特定值。 我这样做:
xtickNames = plt.setp(ax, xticklabels=[str(v) for v in values])
plt.setp(xtickNames)
它有效,但我在屏幕上得到了所有这些内容输出:
agg_filter: unknown alpha: float (0.0 transparent through 1.0 opaque) animated: [True | False] axes: an :class:
~matplotlib.axes.Axes
instance backgroundcolor: any matplotlib color bbox: rectangle prop dict
clip_box: a :class:matplotlib.transforms.Bbox
instance
clip_on: [True | False] clip_path: [ (:class:~matplotlib.path.Path
,
:class:~matplotlib.transforms.Transform
) |
:class:~matplotlib.patches.Patch
| None ] color: any matplotlib color contains: a callable function
family or fontfamily or fontname or name: [FONTNAME | 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' ] figure: a :class:matplotlib.figure.Figure
instance
fontproperties or font_properties: a :class:matplotlib.font_manager.FontProperties
instance
gid: an id string horizontalalignment or ha: [ 'center' | 'right' | 'left' ] label: string or anything printable with '%s' conversion. linespacing: float (multiple of font size) lod: [True | False] multialignment: ['left' | 'right' | 'center' ] path_effects: unknown picker: [None|float|boolean|callable] position: (x,y)
rasterized: [True | False | None] rotation: [ angle in degrees | 'vertical' | 'horizontal' ] rotation_mode: unknown size or fontsize: [size in points | 'xx-small' | 'x-small' | 'small' | 'medium' | 'large' | 'x-large' | 'xx-large' ] sketch_params: unknown snap: unknown
stretch or fontstretch: [a numeric value in range 0-1000 | 'ultra-condensed' | 'extra-condensed' | 'condensed' | 'semi-condensed' | 'normal' | 'semi-expanded' | 'expanded' | 'extra-expanded' | 'ultra-expanded' ]
style or fontstyle: [ 'normal' | 'italic' | 'oblique']
text: string or anything printable with '%s' conversion.
transform: :class:~matplotlib.transforms.Transform
instance
url: a url string variant or fontvariant: [ 'normal' | 'small-caps' ] verticalalignment or va or ma: [ 'center' | 'top' | 'bottom' | 'baseline' ] visible: [True | False]
weight or fontweight: [a numeric value in range 0-1000 | 'ultralight' | 'light' | 'normal' | 'regular' | 'book' | 'medium' | 'roman' | 'semibold' | 'demibold' | 'demi' | 'bold' | 'heavy' | 'extra bold' | 'black' ]
x: float y: float zorder: any number
出了什么问题?
最佳答案
xtickNames = plt.setp(ax, xticklabels=[str(v) for v in values])
设置xticklabels
属性。
plt.setp(xtickNames)
将 xtickNames
的可配置属性打印到屏幕上。
因此,只需使用第一个命令来设置xticklabels
,而无需打印到屏幕。或者,您可以使用
ax.set_xticklabels(map(str, values))
关于python - matplotlib:设置 xticklabels 返回一些 "help"输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20179843/