我在绘制合适的线时有问题

发布于 2025-01-29 21:29:34 字数 878 浏览 2 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绻影浮沉 2025-02-05 21:29:34

您必须确保jahresmitteltemperaturen具有 的相同维度,我看到的第一个问题是jahresmitteltemperaturen是dataframe,因此有两个尺寸,而多年是一个范围。

您没有显示数据,但是我想这是每行的一个条目,那么您想做的就是为给定的数据列绘制一行。

另外,您可以尝试简单地尝试jahresmitteltemperaturen.plot(),或更一般地 pandas.dataframe.plot

You have to make sure that Jahresmitteltemperaturen has the same dimensions of years, the first problem I see is that Jahresmitteltemperaturen 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文