Antonio Margaretti
Antonio Margaretti

Reputation: 914

Is it possible to create 2-side bar chart using Matplotlib

Is it possible to create something like that using Matplotlib(without gradient colors or/and numbers above every bar) All I found was how to lay charts on top of each other.2-side bar chart

Upvotes: 2

Views: 182

Answers (1)

nonin
nonin

Reputation: 724

To display the reverse histogram using matplotlib.pyplot.hist, negative weights can be put to the values using the parameter weigths.

Minimal example:

import numpy as np
import matplotlib.pyplot as plt

x1 = np.random.random(100)
x2 = np.random.random(100)

plt.hist(x1, facecolor='teal', edgecolor='white', range=(0, 1))
plt.hist(x2, fc='tomato', ec='white', weights=np.full(len(x2), -1), range=(0, 1))
plt.show()

enter image description here

Upvotes: 2

Related Questions