Skip to content Skip to sidebar Skip to footer

Pandas Xlabel Does Not Show Values

I have a pandas dataframe jul.head() which contains However, when I try to plot my data, I can't figure out how to show my index values (small swarm size, medium high swarm size

Solution 1:

Following should do:

df1=pd.DataFrame({'config name':['small', 'medium', 'large'], 'value':[-.000127, .000169, -.000206]})
plt.plot(df1.iloc[:,0], df1.iloc[:,1])
plt.xlabel('Config name')
plt.ylabel('Value')
plt.legend('Value')

Solution 2:

This should work fine in pandas 0.20. For some reason newer versions of pandas kill the ticklabels.

import matplotlib.pyplotas plt
import pandas as pd

df = pd.DataFrame({"value" : [0.1, 0.3, 0.2]}, index=list("ABC"))

ax = df.plot(y='value', label='july')
ax.set_xlabel("pandas "+pd.__version__, fontsize=12)

plt.show()

v 0.20.1

enter image description here

v 0.23.1

enter image description here

You can set the ticklabels yourself in pandas 0.23

ax.set_xticks(range(len(df.index)))
ax.set_xticklabels(df.index)

enter image description here

Or you can use matplotlib for plotting, as shown e.g. in this answer.

Post a Comment for "Pandas Xlabel Does Not Show Values"