Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas/matplotlib line plot does not show x axis text labels

Issue

Plotting data from a DataFrame into a line plot excludes "dates" on the x axis.

north_result = list(data.aggregate(pipeline))

dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
north_result_df.plot.line()

enter image description here

Line plot requires dates just above 'months' on the x axis. Dates show if they are numeric and not strings...any help would be greatly appreciated! As you can tell i am pretty new to Pandas...

Solution

north_result = list(data.aggregate(pipeline))

dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
plt.plot(north_result_df.index, north_result_df["total"])
plt.show()
like image 962
bsod_ Avatar asked May 26 '26 10:05

bsod_


1 Answers

you can use pyplot

import matplotlib.pyplot as plt
north_result =[5,6,7,2,8,5,4,8,9,4,1,5]
dates =['Jun','Jul','Aug','Sep','Oct','Nov','Dec','Jan','Feb','Mar','Apr','May']
north_result_df = pd.DataFrame(north_result, index=dates)
north_result_df.index.name = 'Months'
plt.plot(north_result_df)
plt.show()

the result will be like:

enter image description here

like image 56
Rehim Alizadeh Avatar answered May 28 '26 00:05

Rehim Alizadeh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!