简体   繁体   中英

Smoothing the curve in a line plot - Values interval x axis

I'm trying to recreate the following plot:

source_plot

With an online tool I could create the dataset (135 data points) which I saved in a CSV file with the following structure:

Year,Number of titles available
1959,1.57480315
1959,1.57480315
1959,1.57480315
...
1971,221.4273356
1971,215.2494175
1971,211.5426666

I created a Python file with the following code:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('file.csv')

df.plot.line(x='Year', y='Number of titles available')

plt.show()

and I'm getting the following plot:

错误的情节

  1. What can I do to get a smooth line like in the original plot?
  2. How can I have the same values in the x axis like in the original plot?

EDIT: I worked on the data set and formatting properly the dates, the plot is now better. This is how the data set looks now:

Date,Number of available titles
1958/07/31,2.908816952
1958/09/16,3.085527674
1958/11/02,4.322502727
1958/12/19,5.382767059
...
1971/04/13,221.6766907
1971/05/30,215.4918154
1971/06/26,211.7808903

This is the plot I can get with the same code posted above:

好情节

The question now is: how can I have the same date range as in the original plot (1958 - mid 1971)?

Try taking the mean of your values that you have grouped by year. This will smooth out the discontinuities that you get each year to an average value. If that does not help, then you should apply any one of numerous filters.

df.groupby('year').mean().plot(kind='line')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM