与xerr和yerr在matplotlib中的散点图。

时间:2022-09-11 22:29:26

i am looking to visualize the positions of two arrays with each other. My Table looks like this

我想把两个数组的位置形象化。我的桌子是这样的。

    Number          Description      value_1  value_2  err_1 err_2
         1          descript_1       124.46   124.46   22.55  54.2
         2          Descript_2       8.20     50.2     0.37   0.1 
         3          Descript_2       52.55    78.3     3.77   2.41
         4          Descript_2       4.33     778.8    0.14   1.78

what i basically want is something like this: 与xerr和yerr在matplotlib中的散点图。

我想要的是这样的:

So in this plot every point has basically three properties: 1. xerror bar 2. yerror bar 3. description what this point represents.

在这个图中,每个点都有三个性质:1。xerror酒吧2。yerror酒吧3。描述这个点代表什么。

I have a feeling that this can be done elegantly with matplotlib, and while i tried some stuff with errorbars that did not quite give me what i would expect. And i have not yet found out how to place the captions in a plot.

我有一种感觉,这可以用matplotlib来优雅地完成,而当我尝试一些带有errorbars的东西时,并没有给出我所期望的东西。而且我还没有发现如何把字幕放在一个情节里。

2 个解决方案

#1


8  

It sounds like you want something like this?

听起来你想要这样的东西?

import matplotlib.pyplot as plt

x = [124.46, 8.20, 52.55, 4.33]
y = [124.46, 50.2, 78.3, 778.8]
xerr = [54.2, 0.1, 2.41, 1.78]
yerr = [22.55, 0.37, 3.77, 0.14]

descrip = ['Atom 1', 'Atom 2', 'Atom 3', 'Atom 4']


plt.errorbar(x, y, xerr, yerr, capsize=0, ls='none', color='black', 
            elinewidth=2)

for xpos, ypos, name in zip(x, y, descrip):
    plt.annotate(name, (xpos, ypos), xytext=(8, 8), va='bottom',
                textcoords='offset points')

plt.show()

与xerr和yerr在matplotlib中的散点图。

errorbar works just like plot. If you want a "scatter" plot then you need to specify linestyle='none' (or equivalently, ls='none'). Based on your drawing, you don't want caps on the errorbars, so I've specified capsize=0. Similarly, you seem to want fairly thick lines for the errorbars, thus elinewidth=2.

errorbar就像plot一样。如果您想要一个“散点”图,那么您需要指定linestyle='none'(或相等地,ls='none')。根据您的绘图,您不需要在errorbars上设置上限,所以我指定了capsize=0。类似地,对于errorbars,您似乎需要相当粗的行,因此elinewidth=2。

If you want a marker in addition to the errorbars, just specify marker='o' (or any marker style you'd like) to errorbar.

如果您想在errorbars之外添加标记,只需指定标记='o'(或您想要的任何标记样式)到errorbar。

annotate is the easiest way to annotate points on a plot. Here, I've specified that the annotation should be placed 8 points above and to the right of each measurement.

注释是在一个情节上注释点的最简单方法。在这里,我已经指定注释应该放在上面的8个点和每个度量的右边。

#2


0  

Won't

不会

import matplotlib.pyplot as plt

x = [100, 200, 300, 400]
y = [100, 200, 300, 400]
xerr = [100, 100, 100, 100]
yerr = [20, 20, 20, 20]

plt.errorbar(x, y, xerr, yerr, ls='none')
plt.show()

mean the error bars are on the wrong axes?

意思是误差条在错误的轴上?

pyplot.errorbar:

pyplot.errorbar:

matplotlib.pyplot.errorbar(x, y, yerr=None, xerr=None, fmt=u'', ecolor=None, elinewidth=None, capsize=3, barsabove=False, lolims=False, uplims=False, xlolims=False, xuplims=False, errorevery=1, capthick=None, hold=None, **kwargs)

Note that yerr precedes xerr, so

请注意,yerr在xerr之前。

plt.errorbar(x, y, xerr, yerr, ls='none')

makes your error bars be backwards - yerr=xerr, xerr=yerr. A good time to use named args:

使你的误差条是向后的- yerr=xerr, xerr=yerr。这是一个叫args的好时机:

plt.errorbar(x, y, xerr=xerr, yerr=yerr, ls='none')

#1


8  

It sounds like you want something like this?

听起来你想要这样的东西?

import matplotlib.pyplot as plt

x = [124.46, 8.20, 52.55, 4.33]
y = [124.46, 50.2, 78.3, 778.8]
xerr = [54.2, 0.1, 2.41, 1.78]
yerr = [22.55, 0.37, 3.77, 0.14]

descrip = ['Atom 1', 'Atom 2', 'Atom 3', 'Atom 4']


plt.errorbar(x, y, xerr, yerr, capsize=0, ls='none', color='black', 
            elinewidth=2)

for xpos, ypos, name in zip(x, y, descrip):
    plt.annotate(name, (xpos, ypos), xytext=(8, 8), va='bottom',
                textcoords='offset points')

plt.show()

与xerr和yerr在matplotlib中的散点图。

errorbar works just like plot. If you want a "scatter" plot then you need to specify linestyle='none' (or equivalently, ls='none'). Based on your drawing, you don't want caps on the errorbars, so I've specified capsize=0. Similarly, you seem to want fairly thick lines for the errorbars, thus elinewidth=2.

errorbar就像plot一样。如果您想要一个“散点”图,那么您需要指定linestyle='none'(或相等地,ls='none')。根据您的绘图,您不需要在errorbars上设置上限,所以我指定了capsize=0。类似地,对于errorbars,您似乎需要相当粗的行,因此elinewidth=2。

If you want a marker in addition to the errorbars, just specify marker='o' (or any marker style you'd like) to errorbar.

如果您想在errorbars之外添加标记,只需指定标记='o'(或您想要的任何标记样式)到errorbar。

annotate is the easiest way to annotate points on a plot. Here, I've specified that the annotation should be placed 8 points above and to the right of each measurement.

注释是在一个情节上注释点的最简单方法。在这里,我已经指定注释应该放在上面的8个点和每个度量的右边。

#2


0  

Won't

不会

import matplotlib.pyplot as plt

x = [100, 200, 300, 400]
y = [100, 200, 300, 400]
xerr = [100, 100, 100, 100]
yerr = [20, 20, 20, 20]

plt.errorbar(x, y, xerr, yerr, ls='none')
plt.show()

mean the error bars are on the wrong axes?

意思是误差条在错误的轴上?

pyplot.errorbar:

pyplot.errorbar:

matplotlib.pyplot.errorbar(x, y, yerr=None, xerr=None, fmt=u'', ecolor=None, elinewidth=None, capsize=3, barsabove=False, lolims=False, uplims=False, xlolims=False, xuplims=False, errorevery=1, capthick=None, hold=None, **kwargs)

Note that yerr precedes xerr, so

请注意,yerr在xerr之前。

plt.errorbar(x, y, xerr, yerr, ls='none')

makes your error bars be backwards - yerr=xerr, xerr=yerr. A good time to use named args:

使你的误差条是向后的- yerr=xerr, xerr=yerr。这是一个叫args的好时机:

plt.errorbar(x, y, xerr=xerr, yerr=yerr, ls='none')