Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib: setting xticklabels returned some "help" output

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().

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

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

What went wrong?

like image 982
Ricky Robinson Avatar asked May 26 '26 06:05

Ricky Robinson


1 Answers

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

sets the xticklabels property.

plt.setp(xtickNames)

prints the configurable properties of xtickNames to the screen.

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

ax.set_xticklabels(map(str, values))
like image 162
unutbu Avatar answered May 27 '26 21:05

unutbu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!