Reputation: 523
I am having trouble labeling the x ticks of a graph with the index values in the series x
that I've created. Below is the code
import matplotlib.pyplot as plt
import pandas as pd
x = pd.Series([421, 122, 275, 847, 175])
index_values = ['2014-01-01', '2014-01-02', '2014-01-03', '2014-01-04',
'2014-01-05']
x.index = index_values
x.plot()
plt.show()
This is the graph that is returned (without ticks on the x-axis):
So my question is: How do I label the x ticks with the dates in index_values
(which are also the indexes in the Series x
) ?
Upvotes: 2
Views: 84
Reputation: 12128
You can set xticks directly through the following:
plt.xticks(x.index, index_values)
Upvotes: 1
Reputation: 154
You can just put a label to the axis with the provided methods, as shown below:
plt.ylabel('my Y label')
plt.xlabel('my X label')
plt.show()
Upvotes: 0