Reputation: 377
I have load a time series dataset in pandas(date/time and kwh) and I would like to build a histogram.I'm confused with the syntax.I used this(plt.hist(data.kwh)) but the result wasn't good.
Upvotes: 0
Views: 121
Reputation: 69755
matplotlib.pyplot.hist(samples, bins = 101)
where samples is an array and bins is the number of bins you want in your histogram.
Alternatively, you can use pylab to performm this task:
pylab.hist(samples, bins = 101)
Upvotes: 1
Reputation: 229
Ideally when you build your histogram you should also use the "bins" parameter to make enough bins to hold your data.
import matplotlib.pyplot as plt
from math import ceil
# Load data as data.kwh
spacing = 10 # size on x axis of the bin to aim for
bins = ceil((data.kwh.max() - data.kwh.min()) / spacing)
plt.hist(data.kwh, bins=bins)
plt.show()
Upvotes: 1