Jason H
Jason H

Reputation: 13

Use DataFrame index as x-axis ticks

I have a DataFrame with an Index (Time) and one column (Rate). I'd just like to use the Time as the x-ticks in a histogram plot and Rate as the y axis.

Here is what I've got so far:

data = pd.DataFrame.from_dict(rates,orient='index')
data.index.name = 'Time'
data.columns = ['Rate']
data.plot(kind='hist', x = data.index.values)

print(data) produces:

          Rate
Time          
0     1.191309
1     1.208280
2     1.244835
3     1.279342
4     1.307912
5     1.532720

Upvotes: 1

Views: 1495

Answers (1)

MaxU - stand with Ukraine
MaxU - stand with Ukraine

Reputation: 210842

Demo:

import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')

Source DF:

In [122]: data
Out[122]:
          Rate
Time
0     1.191309
1     1.208280
2     1.244835
3     1.279342
4     1.307912
5     1.532720

Bar-plot:

In [126]: data.plot.bar(rot=0)
Out[126]: <matplotlib.axes._subplots.AxesSubplot at 0xe1fe048>

enter image description here

Histogram plot:

In [131]: data.plot.hist(rot=0)
Out[131]: <matplotlib.axes._subplots.AxesSubplot at 0xe7611d0>

enter image description here

Upvotes: 1

Related Questions