Reputation: 9139
I want to plot a histogram with three columns with heights 5
, 10
and 20
. Each column will have a width of 1. So the first column will have height 5
on the interval [0,1]
, the second one 10
on the interval [1,2]
and so on.
plt.hist([5, 10, 20], bins=range(0,4,1))
plt.show()
What did I do wrong?
Upvotes: 1
Views: 103
Reputation: 65460
hist
computes the number of data samples that lies within a given bin and then displays the resulting frequencies as a bar plot. You don't actually need hist
because you already have the frequencies. You simply need bar
to display these frequencies as a bar plot. The first input specifies the left edge location of each bar and then we can use the width
kwarg to specify the width of each bar.
import matplotlib.pyplot as plt
plt.bar([0, 1, 2], [5, 10, 20], width=1)
Upvotes: 2