matplotlib:设置xticklabel返回一些“帮助”输出。

时间:2023-01-07 23:36:45

I have a dozen boxplots on the same plot, arranged horizontally. I want the spacing between them to be constant, so I didn't set positions when calling plt.boxplot().

我在同一块土地上有十几个箱子,水平排列。我希望它们之间的间隔是常量,所以我在调用plt.boxplot()时没有设置位置。

For each boxplot, I want the corresponding label on the X-axis to have a certain value. I do this:

对于每个boxplot,我希望在x轴上对应的标签具有一定的值。我这样做:

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

It works, but I get all this stuff output on screen:

它是有效的,但是我把所有这些东西都输出到屏幕上:

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

agg_filter: unknown alpha: float(0.0透明到1.0不透明)动画:[True | False]轴:a:类:~matplotlib.ax。轴实例backgroundcolor:任何matplotlib颜色bbox:矩形道具命令clip_box: a:类:matplotlib.transform。Bbox实例clip_on: [True | False] clip_path: [(:class:~matplotlib.path)。路径:类:~ matplotlib.transforms.Transform)|:类:~ matplotlib.patches。[font - family:宋体;mso - ascii - font - family: tahoma; mso - hansi - font - family: calibri; mso - hansi - font - family: tahoma ' >项目名称:< / span > < span图形实例fontproperties或font_properties: a:类:matplotlib.font_manager。属性实例gid: id字符串水平对齐或ha: ['center' | 'right' | 'left']标签:字符串或任何可打印的与'%s'转换。linespacing:浮动(字体大小的倍数)lod:[真|假]multialignment:[“左”|“对”|“中心”)path_effects:未知的选择:(布尔| | |浮动没有一个可调用的)位置:(x,y)光栅:[真|假|没有]旋转:[在度|“垂直”|“水平”]rotation_mode:未知的大小或字形大小:[大小分|“xx-small”|“x-small”|“小”|“介质”|“大型”|“超大号”|“xx-large”]sketch_params:未知的吸附:未知的拉伸或fontstretch:|“|”的|“|”“|”“|”“|”“|”“|”的“|”“|”“|”的“|”“|”的“|”的“|”“超扩展”的“|”“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“|”的“变换::类:~ matplotlib.transforms。变换实例url:url字符串变体或fontvariant:['正常' | '小型大写字母']verticalalignment马或va:[“中心”|“*”|“底部”|“基线”)可见:[真|假]体重或fontweight:[一个数值范围0 - 1000 |“超轻”|“光”|“正常”|“常规”|“书”|“介质”|“罗马”|“半黑体的”|“demibold”|“黛米”|“大胆”|“沉重”|“额外的大胆”| '黑色']x:浮动y:浮动zorder:任何号码

What went wrong?

到底是哪里出了错?

1 个解决方案

#1


1  

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

sets the xticklabels property.

集xticklabels属性。

plt.setp(xtickNames)

prints the configurable properties of xtickNames to the screen.

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

So just use the first command to set the xticklabels without printing to the screen. Alternatively, you could use

因此,只需使用第一个命令来设置xticklabel,而无需打印到屏幕。或者,您可以使用

ax.set_xticklabels(map(str, values))

#1


1  

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

sets the xticklabels property.

集xticklabels属性。

plt.setp(xtickNames)

prints the configurable properties of xtickNames to the screen.

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

So just use the first command to set the xticklabels without printing to the screen. Alternatively, you could use

因此,只需使用第一个命令来设置xticklabel,而无需打印到屏幕。或者,您可以使用

ax.set_xticklabels(map(str, values))