我无法绘制错误我确切想要的

发布于 2025-01-22 08:46:29 字数 746 浏览 0 评论 0原文

我想在两个方向上都用错误栏绘制。我的错误值是标准错误。因此,我希望误差线按照它们所属的价值。这是我的代码:

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

column_names = ["gplx", "gplxerror", "hplx", "hplxerror"]
data=pd.read_csv("hw4.csv", names=column_names)

x=data.gplx.to_list()
xerr=data.gplxerror.to_list()
y=data.hplx.to_list()
yerr=data.hplxerror.to_list()

xx = [1/(i/1000) for i in x]
yy = [1/(j/1000) for j in y]

plt.errorbar(xx, yy, xerr, yerr, fmt='o',
             ecolor='pink', color='blue')
plt.xlabel('Gaia Distance(in pc)')
plt.ylabel('Hipparcos Distance (in pc)')
plt.savefig('filename.png', dpi=600)

这是我得到的绘图:

“我的绘图”

但是错误栏太大了。我该如何使它们更小?

I want to plot with error bars in both directions. My error values are standard error. So I want the error bars to be according to the value they belong to. Here's my code:

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

column_names = ["gplx", "gplxerror", "hplx", "hplxerror"]
data=pd.read_csv("hw4.csv", names=column_names)

x=data.gplx.to_list()
xerr=data.gplxerror.to_list()
y=data.hplx.to_list()
yerr=data.hplxerror.to_list()

xx = [1/(i/1000) for i in x]
yy = [1/(j/1000) for j in y]

plt.errorbar(xx, yy, xerr, yerr, fmt='o',
             ecolor='pink', color='blue')
plt.xlabel('Gaia Distance(in pc)')
plt.ylabel('Hipparcos Distance (in pc)')
plt.savefig('filename.png', dpi=600)

And this is the plot that I get:

my plot

But the error bars are too big. How can I make them smaller?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

半葬歌 2025-01-29 08:46:29

我使用(错误/100 *值)作为每个值的百分比获取错误。它运行良好。检查以下代码:


import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

  
column_names = ["gplx", "gplxerror", "hplx","hplxerror"]
data=pd.read_csv("hw42.csv", names=column_names)

x=data.gplx.to_list()
xerr=data.gplxerror.to_list()
y=data.hplx.to_list()
yerr=data.hplxerror.to_list()

xx = [1/(i/1000) for i in x]
yy = [1/(j/1000) for j in y]

xxerr = [(i/100) for i in xerr]
yyerr = [(j/100) for j in yerr]

xe= [a * b for a, b in zip(xx, xxerr)]
ye= [a * b for a, b in zip(yy, yyerr)]

plt.errorbar(xx, yy, xe, ye,fmt='.', alpha=1, ecolor='black',elinewidth=0.5, markersize=4)
plt.xlabel('Gaia Distance(in pc)')
plt.ylabel('Hipparcos Distance (in pc)')
plt.savefig('filename.png', dpi=600)

I used (error/100 * value) to get error as percentage of each value. It worked well. Check the following code:


import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

  
column_names = ["gplx", "gplxerror", "hplx","hplxerror"]
data=pd.read_csv("hw42.csv", names=column_names)

x=data.gplx.to_list()
xerr=data.gplxerror.to_list()
y=data.hplx.to_list()
yerr=data.hplxerror.to_list()

xx = [1/(i/1000) for i in x]
yy = [1/(j/1000) for j in y]

xxerr = [(i/100) for i in xerr]
yyerr = [(j/100) for j in yerr]

xe= [a * b for a, b in zip(xx, xxerr)]
ye= [a * b for a, b in zip(yy, yyerr)]

plt.errorbar(xx, yy, xe, ye,fmt='.', alpha=1, ecolor='black',elinewidth=0.5, markersize=4)
plt.xlabel('Gaia Distance(in pc)')
plt.ylabel('Hipparcos Distance (in pc)')
plt.savefig('filename.png', dpi=600)

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