Skip to content

xtick label setting with improper scale #2980

Closed
@fonnesbeck

Description

@fonnesbeck

I have some data that I have used to generate a stacked bar graph.

by_conclusion = measles_data.groupby(["AGE", "CONCLUSION"])
counts_by_cause = by_conclusion.size().unstack().fillna(0)
ax = counts_by_cause.plot(kind='bar', stacked=True)

However, I get a pretty crowded x-axis:

too_many_ticks

So, I try to use set_xticks to try and thin them out, either as an argument to plot, or as a separate command:

ax.xticks(arange(0,80,10))

However, for some reason, the labels end up being downscaled by a factor of 10:

wrong_ticks

(might be hard to see, but it is printing "0.0, 1.0, 2.0, ..." instead of "0, 10, 20, ...")

Its not clear why this is happening, or how to get around it, so I'm either going about this wrong or its a bug. I get the same behavior when I try using MaxNLocator:

ax.xaxis.set_major_locator( MaxNLocator(nbins = 7) )

The data are here

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions