Matplotlib barh produces a winning interval between bars

I create histograms that look like this:

enter image description here

Note that the vertical distance on the labels is uneven for some reason; I am not sure if this is due to the way I assigned the ticks or some mechanism actually placing the text. Relevant Code:

height_factor = 40.0 ind = np.linspace(0,len(sorted_totals)*height_factor,num=len(sorted_totals)) width = 0.25 fig = plt.figure(figsize=(15.5, 8.75),dpi=300) p1 = plt.barh(ind,map(int,sorted_composite[:,0]),color='blue',align='center',height=height_factor) p1 = plt.barh(ind,map(int,sorted_composite[:,2]),color=(0.75,0.1,0.1),align='center',height=height_factor) plt.ylabel('# of Picks (blue) + # of Bans (red)') plt.yticks(ind, sorted_totals[:,0]) plt.subplots_adjust(bottom=0.05, left=0.14,right=0.95,top=0.95) plt.ylim([ind.min() - height_factor, ind.max() + height_factor]) 

My data is stored in sorted_composite, and ind are the values โ€‹โ€‹that I use to place the columns (ytick locations). I use linspace to create evenly distributed bars, and these are just the kinds of work, and I donโ€™t know exactly why.

+7
source share
1 answer

as user1127062 suggests, maybe your code is ok.

If you donโ€™t need the plot to be interactive, save it as svg

If you run:

 data = numpy.random.randn(10000) pylab.hist(data,300) pylab.savefig(fileName+'.svg',format='svg') 

you will see the alias of the pixels (in bandwidth) in the picture window, but it got into the svg file.

The cairo backend seems to do the best job of saving png files if svg is incompatible with what you are doing. They look as good as a svg screenshot.

You can switch the backend by running.

 import matplotlib # you have to change the backend before importing pylab matplotlib.use('cairo') import pylab 

raw "cairo" does not support show() , so you cannot use it interactively or display a graph directly from the program.

The GTKCairo backend has the best of both worlds, but is not included in the default installation (at least not in what I got with sudo apt-get install matplotlib )

If you are using Ubuntu, I think all you have to do to get it working is to install gtk and recompile matplotlib:

 sudo apt-get install git-core python-gtk2-dev git clone git://github.com/matplotlib/matplotlib.git cd matplotlib sudo python setup.py install 

You can check which of the backends is active:

 matplotlib.get_backend() 

You can automatically load your favorite backend by searching for your matplotlibrc file, I found it in:

 /usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/matplotlibrc 
+1
source

All Articles