Back-to-back bar graphs in matplotlib

There is a nice feature that draws inverse histograms in Matlab. I need to create a similar graph in matplotlib. Can someone show an example of working code?

+3
source share
2 answers

Thanks to the link noted by Mark Rushakov, the next thing I finally did

import numpy as np
from matplotlib import pylab as pl

dataOne = get_data_one()
dataTwo = get_data_two()

hN = pl.hist(dataTwo, orientation='horizontal', normed=0, rwidth=0.8, label='ONE')
hS = pl.hist(dataOne, bins=hN[1], orientation='horizontal', normed=0, 
    rwidth=0.8, label='TWO')

for p in hS[2]:
    p.set_width( - p.get_width())

xmin = min([ min(w.get_width() for w in hS[2]), 
                min([w.get_width() for w in hN[2]]) ])
xmin = np.floor(xmin)
xmax = max([ max(w.get_width() for w in hS[2]), 
                max([w.get_width() for w in hN[2]]) ])
xmax = np.ceil(xmax)
range = xmax - xmin
delta = 0.0 * range
pl.xlim([xmin - delta, xmax + delta])
xt = pl.xticks()
n = xt[0]
s = ['%.1f'%abs(i) for i in n]
pl.xticks(n, s)
pl.legend(loc='best')
pl.axvline(0.0)
pl.show()
+4
source

This matplotlib user mailbox contains sample code for a bigogram that goes up and down instead of left and right. Here is an example of the output with which it is associated.

up-down , , y x.

, MATLAB, script, - 40 . script , MATLAB matplotlib .

+2

Source: https://habr.com/ru/post/1716200/


All Articles