How do I get the x-axis values of [a, b, c] to show up?
import pandas as pd
import matplotlib.pyplot as plt
s = pd.Series([1, 2, 10], index=['a', 'b', 'c'])
s.plot()
plt.show()
MatPlotLib with Python To show all X coordinates (or Y coordinates), we can use xticks() method (or yticks()).
To set Dataframe column value as X-axis labels in Python Pandas, we can use xticks in the argument of plot() method.
You can get your xtick labels to show using plt.xticks
:
import pandas as pd
import matplotlib.pyplot as plt
s = pd.Series([1, 2, 10], index=['a', 'b', 'c'])
s.plot()
plt.xticks(np.arange(len(s.index)), s.index)
plt.show()
Output:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With