python - matplotlib:设置 xticklabels 返回一些 "help"输出

标签 python matplotlib boxplot

我在同一个地 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/

相关文章:

r - Boxplot.stats R 未识别异常值

python - 生成遵循分布的平滑随机数

Python 填充缺失数据

python - "Clean"在 matplotlib 中使用单词作为标记的方法?并使字体大小和颜色不同?

python - Matplotlib 轮廓图有 3 种颜色

python - Matplotlib:如何删除网格线末尾的暗水平/垂直点?

python - 如何使用 hue 参数将中值标签添加到 Seaborn 箱线图

r - ggplot 到 ggplotly 不适用于自定义的 geom_boxplot 宽度

python - 未检测到 Youtube 视频位置

python - 使用 python 重新组织具有一对多关系的列表