简体   繁体   English

如何使用Python和MatPlot删除fill_between()中的连接区域

[英]How to remove connecting area in fill_between() using Python and MatPlot

I am graphing +-2 standard deviations from the mean on my graph (the green points). 我正在用图表的平均值(绿点)绘制+ -2标准偏差。 However, I would rather have straight vertical lines on top of each x-mean, because currently there is a connecting shade area between states that is misleading. 但是,我宁愿在每个x均值的顶部都有一条垂直的垂直线,因为当前状态之间存在连接阴影区域,这会产生误导。 How can I do this? 我怎样才能做到这一点? I've tried everything and can't figure it out. 我已经尝试了所有方法,但无法解决。 Thanks in advance. 提前致谢。 (Since I'm new to Stack Overflow I can't post an image of my graph unfortunately.) (由于我是Stack Overflow的新手,所以我无法发布图形图像。)

plt.scatter(x= joined.index.values, y = joined.poll_mean, color = "g")
plt.scatter(x= joined.index.values, y = joined.spread,color = joined.color)      
plt.fill_between(joined.index,(joined.poll_mean + 2*joined.poll_std).values, (joined.poll_mean - 2*joined.poll_std).values, color='g', alpha = .3)
plt.xticks(joined.index.values, joined.state.values, rotation='vertical')

Are you trying to do error bars? 您是否正在尝试制作错误栏? There is a matplotlib package for that. 有一个matplotlib软件包。

An example piece of code to do this (from here ): 示例代码(从此处开始 ):

import numpy as np
import matplotlib.pyplot as plt

# example data
x = np.arange(0.1, 4, 0.5)
y = np.exp(-x)

# example variable error bar values
yerr = 0.1 + 0.2*np.sqrt(x)
xerr = 0.1 + yerr

# First illustrate basic pyplot interface, using defaults where possible.
plt.figure()
plt.errorbar(x, y, xerr=0.2, yerr=0.4)
plt.title("Simplest errorbars, 0.2 in x, 0.4 in y")

Also as a tip, for people to better help you, provide code that can reproduce your problem in full. 另外,作为提示,为了使人们更好地为您提供帮助,请提供可以完全重现您的问题的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM