python - pyplot.hist histtype = 'step' malfunction depending on data -
i doing lot of plotting , ran weird anomaly pyplot.hist function. i've trimmed program down minimum working example show problem.
import matplotlib.pyplot plt import numpy np var = [25.00, 35.68, 29.02, 25.46, 30.58, 30.86, 38.08, 38.63, 25.19, 32.11, 26.57, 37.23, 37.97, 27.38, 27.25, 33.33, 31.41, 26.93, 28.42, 25.99, 30.09, 31.87, 34.40, 33.46, 31.76, 34.03, 27.01, 27.52, 30.41, 25.84, 25.84] fig = plt.figure() plt.hist(var, histtype = 'step') plt.show() when run script, this:
anomaly http://dl.dropbox.com/u/13695305/figure%201_005.png
however, if remove last 5 elements: 27.01, 27.52, 30.41, 25.84, 25.84, script works fine.
import matplotlib.pyplot plt import numpy np var = [25.00, 35.68, 29.02, 25.46, 30.58, 30.86, 38.08, 38.63, 25.19, 32.11, 26.57, 37.23, 37.97, 27.38, 27.25, 33.33, 31.41, 26.93, 28.42, 25.99, 30.09, 31.87, 34.40, 33.46, 31.76, 34.03] fig = plt.figure() plt.hist(var, histtype = 'step') plt.show() working! http://dl.dropbox.com/u/13695305/figure%201_004.png
this driving me crazy! i've tried using numpy arrays, , didn't help. numpy random worked no problem. reason, specific data set (type?) causes fail. have idea why?
edit: important note function works fine histtype = 'bar', bug arises histtype = 'step'. can recreate problem.
unfortunately it's bug, there's fix: manually set ymin plot.
import matplotlib.pyplot plt import numpy np var = [[25.00, 35.68, 29.02, 25.46, 30.58, 30.86, 38.08, 38.63, 25.19, 32.11, 26.57, 37.23, 37.97, 27.38, 27.25, 33.33, 31.41, 26.93, 28.42, 25.99, 30.09, 31.87, 34.40, 33.46, 31.76, 34.03, 27.01, 27.52, 30.41, 25.84, 25.84]] fig, ax = plt.subplots()#figsize = (10, 10)) ax.hist(var[0],histtype = 'step') plt.ylim(ymin=0) plt.show() the bug seems fixed v1.3, however. apparently i'm using earlier version.
>>> matplotlib.__version__ '1.1.1rc' so upgrading matplotlib fix problem.
Comments
Post a Comment