Eugene_Harold
Eugene_Harold

Reputation: 523

How to get labeled x-values to this Series graph?

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): There are no markings 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

Answers (2)

Yaakov Bressler
Yaakov Bressler

Reputation: 12128

You can set xticks directly through the following:

plt.xticks(x.index, index_values) 

Upvotes: 1

jufx
jufx

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

Related Questions