[英]skip the first error of a matplotlib errorbar
When trying to plot an errorbar using matplotlib and skipping the first error I ran into some difficulties.当尝试使用plot使用 matplotlib 并跳过第一个错误时,我遇到了一些困难。 What I want is to plot an errorbar but to skip the first value for the plot.
我想要的是 plot 一个错误栏,但跳过 plot 的第一个值。
So I tried to adapt a matplotlib example as follows:所以我尝试改编一个 matplotlib 示例如下:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
x = np.arange(10)
y = 2.5 * np.sin(x / 20 * np.pi)
yerr = np.linspace(0.05, 0.2, 10)
plt.errorbar(x, y + 3, yerr=yerr, label='both limits (default)')
lim = [False]+[True]*9
plt.errorbar(x, y + 1, yerr=yerr, uplims=lim, lolims=lim,
label='only last 9 values with error visualized')
plt.legend(loc='lower right')
So I tried to use uplims
and lowlims
and get rid of the arrow tips later.所以我尝试使用
uplims
和lowlims
并在以后摆脱箭头提示。 What's happening when I set the upper and lower limit to False
is that a normal error is plotted instead of none.当我将上限和下限设置为
False
时发生的情况是绘制了正常错误而不是没有绘制。 The desired output and my approach is shown in the following figure:想要的output和我的做法如下图所示:
I'm aware of the errorevery
parameter of the errorbar, but as I only want to skip the first error I think it's not applicable to my problem.我知道错误栏的
errorevery
参数,但由于我只想跳过第一个错误,我认为它不适用于我的问题。
Some kind of workaround could be to first plot a normal line with the values, then get rid of the first entry and plot an errorbar for the remaining values.某种解决方法可能是首先将 plot 与值的正常行删除,然后删除第一个条目和 plot 剩余值的错误栏。 I'm asking if there's a better solution to this?
请问有没有更好的办法解决这个问题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.