我在编写代码制作一张柱状图,其中包括一些正数和负数 - 查看这里
简而言之,我想做的是将所有负值作为绿色部分并覆盖到正面,以便您可以看到这些值的不对称性。我尝试了几种方法来实现这个目标,但好像找不到一个很好的答案。
目前为止我已经写了相关代码(我希望没有漏掉重要的内容来制图...):
import glob
import pyrap.images as pim
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
import matplotlib.mlab as mlab
from scipy.optimize import *
less_than_expected_min = -500
more_than_expected_max = 1200
n_bins = 100
bin_edges = np.linspace(less_than_expected_min, more_than_expected_max, n_bins)
for i in range(total):
all_clipped_values = np.zeros([total,n_bins-1])
clipped_levels= np.sum(all_clipped_values,axis=0)
reflect= np.concatenate([clipped_levels[0:30], clipped_levels[30:0]])
plt.bar(bin_edges[:-1],clipped_levels,width=(more_than_expected_max -less_than_expected_min)/float(n_bins), log=True,color='green')
plt.bar(bin_edges[:-1],reflect,width=(more_than_expected_max -less_than_expected_min)/float(n_bins), log=True,color='red')
尝试使用这种方法时,我的问题是我得到了“AssertionError:不兼容的大小:参数'height'必须是长度为99或标量。” 对于我来说并不太清楚如何解决这个问题,实际上是否有比我想象中更简单的反射方法也不确定。欢迎任何反馈-谢谢!
for i in range...
部分:它在每次迭代中将相同的值分配给all_clipped_values
... - Daneel