简体   繁体   English

平滑直线中的曲线 plot - 值区间 x 轴

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

I'm trying to recreate the following plot:我正在尝试重新创建以下 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:使用在线工具,我可以创建我保存在 CSV 文件中的数据集(135 个数据点),其结构如下:

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:我使用以下代码创建了一个 Python 文件:

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:我得到以下 plot:

错误的情节

  1. What can I do to get a smooth line like in the original plot?我该怎么做才能获得像原来的 plot 一样的平滑线?
  2. How can I have the same values in the x axis like in the original plot?如何在 x 轴上获得与原始 plot 相同的值?

EDIT: I worked on the data set and formatting properly the dates, the plot is now better.编辑:我处理数据集并正确格式化日期,plot 现在更好。 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:这是 plot 我可以使用上面发布的相同代码获得:

好情节

The question now is: how can I have the same date range as in the original plot (1958 - mid 1971)?现在的问题是:我如何才能拥有与原始 plot(1958 - 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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