简体   繁体   English

使用 matplotlib 的 fill_between 函数出现意外值错误

[英]Unexpected value error using fill_between function of matplotlib

I've written a straight-forward code that plots two lines.我写了一个简单的代码,绘制了两行。 Then I try to fill the region between them using fill_between but I get this weird error that I don't understand:然后我尝试使用 fill_between 填充它们之间的区域,但出现了我不明白的奇怪错误:

File "C:\\Python27\\lib\\site-packages\\matplotlib\\axes_axes.py", line 5101, in fill_between 'is not 1-dimensional.') ValueError: Input passed into argument "u'x'"is not 1-dimensional.文件“C:\\Python27\\lib\\site-packages\\matplotlib\\axes_axes.py”,第 5101 行,在 fill_between '不是一维的。')ValueError:输入传递到参数“u'x”不是 1-维。

Here is my code sample, where q, DelTheta5, DelTheta50, DelTheta95 are each np arrays of the same dimension and size,这是我的代码示例,其中 q、DelTheta5、DelTheta50、DelTheta95 都是相同维度和大小的 np 数组,

import matplotlib.pyplot as plt 
plt.figure(1)
#fig1, ax1 = plt.subplots()
plt.plot(q, DelTheta5, linewidth=2, linestyle='dashed', color='black')
plt.plot(q ,DelTheta50, linewidth=2, color='black')
plt.plot(q, DelTheta95, linewidth=2, linestyle='dotted', color='black')
plt.fill_between(q, DelTheta5, DelTheta95)

I can get it to work with a different example I found online that uses random data.我可以让它与我在网上找到的使用随机数据的不同示例一起使用。 But it doesn't work for me with the data and code snippet above (the syntax looks correct to me).但是上面的数据和代码片段对我不起作用(语法对我来说是正确的)。 Does anybody know the source of this ValueError?有人知道这个 ValueError 的来源吗? My data arrays are clean (all elements are floats).我的数据数组很干净(所有元素都是浮点数)。 I'm using python 2.7.18.我正在使用 python 2.7.18。

Thanks for your help谢谢你的帮助

@Leonard's comment was exactly correct. @Leonard 的评论完全正确。 I needed to use np.squeeze since there was an extra dimension in my data arrays: ie they were column vectors [] but had an extra ([]) around them.我需要使用 np.squeeze 因为我的数据数组中有一个额外的维度:即它们是列向量 [] 但周围有一个额外的 ([]) 。

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

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