【发布时间】:2017-03-20 15:26:53
【问题描述】:
我在图表中绘制 2 条线,我想在中间的区域加阴影,但是我无法做到,我的数据是 2 个 DataFrames,有 365 个观察值。 我目前的代码是这样的。
plt.figure()
plt.plot(minimos, '', maximos, '')
plt.scatter(df6x, df6, s=50, c='r', alpha=0.8)
plt.scatter(df5x, df5, s=50, c='b', alpha=0.8)
plt.legend(['High', 'Low'])
有关 DataFrame 的更多信息
print(type(maximos),type(minimos), type(x))
print(maximos.shape, minimos.shape,x.shape)
<class 'numpy.ndarray'> <class 'numpy.ndarray'> <class 'numpy.ndarray'>
(365, 1) (365, 1) (365, 1)
但我仍然遇到 ValueError 的问题:参数维度不兼容
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
maximos = maximos.values
minimos = minimos.values
x = np.arange(0,365,1)
x = x.reshape(365,1)
fig = plt.figure()
plt.plot(x, maximos, c='r', alpha=0.8)
plt.plot(x, minimos, c='b', alpha=0.8)
# fill between hgh and low
ax = fig.gca()
ax.fill_between(x, minimos, maximos, facecolor='purple')
plt.legend(['High', 'Low'])
plt.scatter(df6x, df6, s=50, c='r', alpha=0.8)
plt.scatter(df5x, df5, s=50, c='b', alpha=0.8)
错误在这行代码 ax.fill_between(x, minimos, maximos, facecolor='purple')。
【问题讨论】:
标签: python matplotlib