我在绘制合适的线时有问题
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats
Jahresmitteltemperaturen = pd.read_csv('..Not showing because of Data reasons ..')
years = range (1979, 2022)
for year in years:
plt.plot(years, Jahresmitteltemperaturen)
plt.plot(years, Jahresmitteltemperaturen, 'ro')
plt.ylim(258,264)
plt.title('Jahresmitteltemperaturen im Zeitraum von 1979 bis 2022 in der Arktis')
plt.ylabel('Jahresmitteltemperaturen')
plt.xlabel('Jahre 1979 bis 2022')
plt.grid(True)
slope, intercept = stats.linregress(years,Jahresmitteltemperaturen)
Steigung = intercept + slope*years
plt.plot(years,Steigung, color="green")
试图用1979年至2022年的数据绘制图表,并绘制一个拟合线,显示数据的斜率。但是我得到此错误代码“串联轴必须完全匹配的所有输入阵列维数,但是沿尺寸1,索引0处的数组具有尺寸43,而索引1处的数组具有尺寸1”。我是否必须进行从数据框架到其他事物的某种转换? Jahresmitteltemperaturen是一个具有43号尺寸和浮点数的数据框架。
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats
Jahresmitteltemperaturen = pd.read_csv('..Not showing because of Data reasons ..')
years = range (1979, 2022)
for year in years:
plt.plot(years, Jahresmitteltemperaturen)
plt.plot(years, Jahresmitteltemperaturen, 'ro')
plt.ylim(258,264)
plt.title('Jahresmitteltemperaturen im Zeitraum von 1979 bis 2022 in der Arktis')
plt.ylabel('Jahresmitteltemperaturen')
plt.xlabel('Jahre 1979 bis 2022')
plt.grid(True)
slope, intercept = stats.linregress(years,Jahresmitteltemperaturen)
Steigung = intercept + slope*years
plt.plot(years,Steigung, color="green")
Trying to plot a diagramm with Data from the years 1979 to 2022 and a fitted line which shows the slope of the Data. But i get this error code "all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 43 and the array at index 1 has size 1". Do i have to do some kind of conversions from DataFrame to something else? Jahresmitteltemperaturen is a DataFrame with size 43 and float numbers in it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须确保
jahresmitteltemperaturen
具有年
的相同维度,我看到的第一个问题是jahresmitteltemperaturen
是dataframe,因此有两个尺寸,而多年是一个范围。您没有显示数据,但是我想这是每行的一个条目,那么您想做的就是为给定的数据列绘制一行。
另外,您可以尝试简单地尝试
jahresmitteltemperaturen.plot()
,或更一般地 pandas.dataframe.plotYou have to make sure that
Jahresmitteltemperaturen
has the same dimensions ofyears
, the first problem I see is thatJahresmitteltemperaturen
is a dataframe, thus has two dimensions, while years is a range.You are not showing the data, but I suppose it is one entry per row, then maybe what you want to do is to plot a line for a given column of the data.
Alternatively you could try simply
Jahresmitteltemperaturen.plot()
, or more generally pandas.DataFrame.plot