3

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?

1 Answer 1

2
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))
1
  • So I don't even need to save to a variable the output of that first line, right? Nov 24, 2013 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.