long time lurker for programming questions, first time poster.
I am writing some code where I am making a bar graph of a bunch of values, some of which are negative and some of which are positive- plot here
In short, what I want to do is take all the negative values for the green part and overlay them onto the positive side, so you can see the asymmetry in those values. I have tried a few methods to get this to work, and perhaps I'm not searching the correct things but can't seem to find a good answer on how to do this.
The relevant code I have so far (hopefully not leaving anything out that's important for the purposes of the plot...):
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')
The issue when I try this method, however, is I get "AssertionError: incompatible sizes: argument 'height' must be length 99 or scalar." It's not quite clear to me how to solve this, or in fact if there is a simpler way to do this reflection than what I'm thinking.
Any feedback appreciated- thanks!
As I mentioned in my comment, maybe this will clarify
>>> x = list(range(100))
>>> x[0:30]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
>>> x[30:0]
[]
>>> x[30:0:-1]
[30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
You have to specify the negative step.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With