-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
xtick label setting with improper scale #2980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Closing as duplicate of #7612 |
re-opening as not fixed by #26185 |
Data posted by @fonnesbeck is not available anymore So I am trying to build a small reproducible example, I will leave it here in case it helps someone: import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
n = 200
ages = np.random.choice(np.arange(0, 81), n)
outcome = np.random.choice(["Clinical", "Confirmed", "Discarded"], n)
df = pd.DataFrame({
"conclusion": outcome,
"age": ages
})
print(df)
# conclusion age
# 0 Discarded 74
# 1 Confirmed 63
# ...
counts = df.groupby(["conclusion", "age"]).size().unstack().fillna(0)
print(counts)
# age 0 1 2 3 4 5 ... 75 76 77 78 79 80
# conclusion ...
# Clinical 1.0 0.0 0.0 1.0 1.0 0.0 ... 1.0 2.0 0.0 2.0 1.0 0.0
# Confirmed 1.0 1.0 1.0 0.0 2.0 1.0 ... 0.0 1.0 1.0 0.0 1.0 1.0
# Discarded 0.0 1.0 1.0 1.0 1.0 2.0 ... 1.0 0.0 1.0 0.0 0.0 1.0
ax = counts.plot(kind='bar', stacked=True)
plt.show() However the result is quite different in pandas version |
So I am trying to build a completely different example, more minimalistic to show the error, but everything is working fine for me: import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
n = 80
df = pd.DataFrame({"Clinical": np.random.choice([0, 1, 2, 3], n),
"Confirmed": np.random.choice([0, 1, 2, 3], n),
"Discarded": np.random.choice([0, 1, 2, 3], n),
}, index=np.arange(0, n))
ax = df.plot(kind='bar', stacked=True) if we try: ax.xticks(np.arange(0,80,10))
AttributeError: 'AxesSubplot' object has no attribute 'xticks' but using ax.set_xticks(np.arange(0,80,10)) will produce the desired result So I am not sure if this issue should be marked as information needed or if it is already solutioned. @jreback and @mroeschke. |
@NumberPiOso thanks for investigating. If all appears well for your minimal example might be good to add your example as a unit test. |
I have some data that I have used to generate a stacked bar graph.
However, I get a pretty crowded x-axis:
So, I try to use
set_xticks
to try and thin them out, either as an argument to plot, or as a separate command:However, for some reason, the labels end up being downscaled by a factor of 10:
(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
:The data are here
The text was updated successfully, but these errors were encountered: