本文介绍了使用matplotlib在x-y散点图中的误差线的颜色图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个时间序列的数据,其数量为y,其误差为yerr.我现在想创建一个显示y与相位(即时间/周期%1)的垂直误差条(yerr)的图.为此,我通常使用pyplot.errorbar(time,y,yerr = yerr,...)

I have a time series of data for which I have the quantity, y, and its error, yerr. I would now like to create a plot that shows y against phase (i.e. time / period % 1) with vertical errorbars (yerr). For this, I typically use pyplot.errorbar(time, y, yerr=yerr, ...)

但是,我想使用一个颜色条/贴图来指示同一图中的时间值.

However, I would like to use a colorbar/map to indicate the value of time in this same plot.

我的工作是:

pylab.errorbar( phase, y, yerr=err, fmt=None, marker=None, mew=0 )
pylab.scatter( phase, y, c=time, cmap=cm )

不幸的是,这将绘制单色错误栏(默认为蓝色).由于每个图有约1600个点,因此这使散点图的色图消失在误差线的后面.这是一张图片,显示我的意思:

Unfortunately, this will plot unicolored errorbars (default is blue). Since I have ~1600 points per plot, this makes the colormap of the scatter plot disappear behind the error bars. Here's a picture shows what I mean:

有没有一种方法可以使用与散点图中使用的颜色图相同的颜色图来绘制误差线?我不想调用错误栏1600次...

Is there a way that I can get the error bars to be plotted using the same colormap as the one used in the scatter plot? I don't want to call errorbar 1600 times...

推荐答案

除了更改颜色外,另一个建议是更改误差线与散点图的zorder.这将使用户专注于数据并绘制出错误的一般形状(我认为这是您的意图).

In addition to changing the color, another suggestion is to change the zorder of the error bars versus the scatter plot. This focuses the user on the data and draws out the general shape of the errors (which I think is your intention).

from pylab import *

# Generate some random data that looks like yours
N = 1000
X = random(N)
Y = sin(X*5) + X*random(N)*.8
Z = random(N)
ERR = X*random(N)

# These are the new arguments that I used
scatter_kwargs = {"zorder":100}
error_kwargs = {"lw":.5, "zorder":0}

scatter(X,Y,c=Z,**scatter_kwargs)
errorbar(X,Y,yerr=ERR,fmt=None, marker=None, mew=0,**error_kwargs )
xlim(0,1)
show()

这篇关于使用matplotlib在x-y散点图中的误差线的颜色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:56