Python - matplotlib axes limits approximate ticker location -
when no axes limits specified, matplotlib chooses default values nice, round numbers below , above minimum , maximum values in list plotted.
sometimes have outliers in data , don't want them included when axes selected. can detect outliers, don't want delete them, have them beyond area of plot. have tried setting axes minimum , maximum value in list not including outliers, means values lie on axes, , bounds of plot not line ticker points.
is there way specify axes limits should in range, let matplotlib choose appropriate point?
for example, following code produces nice plot y-axis limits automatically set (0.140,0.165):
from matplotlib import pyplot plt plt.plot([0.144490353418, 0.142921640661, 0.144511781706, 0.143587888773, 0.146009766101, 0.147241517391, 0.147224266382, 0.151530932135, 0.158778411784, 0.160337332636]) plt.show()
after introducing outlier in data , setting limits manually, y-axis limits set below 0.145 , above 0.160 - not neat , tidy.
from matplotlib import pyplot plt plt.plot([0.144490353418, 0.142921640661, 0.144511781706, 0.143587888773, 500000, 0.146009766101, 0.147241517391, 0.147224266382, 0.151530932135, 0.158778411784, 0.160337332636]) plt.ylim(0.142921640661, 0.160337332636) plt.show()
is there way tell matplotlib either ignore outlier value when setting limits, or set axes 'below 0.142921640661' , 'above 0.160337332636', let decide appropriate location? can't round numbers , down, datasets occur on different scale of magnitude.
you make data
masked array:
from matplotlib import pyplot plt import numpy np data = [0.144490353418, 0.142921640661, 0.144511781706, 0.143587888773, 500000, 0.146009766101, 0.147241517391, 0.147224266382, 0.151530932135, 0.158778411784, 0.160337332636] data = np.ma.array(data, mask=false) data.mask = data>0.16 plt.plot(data) plt.show()
Comments
Post a Comment