number_on_axis: how many ticks we want to show on the axis
data: the data to plot
In order to have a desired number of ticks and using the data values as the tickvalues, we can define the xticks by ourselves. For example,
plot(data)
if len(data)/float(number_on_axis) != len(data)/int(number_on_axis):
xlen = (len(data)/number_on_xaxis+1)*number_on_axis
else:
xlen = len(data)
xlim([0,xlen])
xres = xlen/number_on_xaxis
xtickval = tuple("%.1f" % round(i, 1) for i in data[0:-1:xres])
xticknum = arange(0,len(data),xres)
xticks(xticknum, xtickval)
Aucun commentaire:
Enregistrer un commentaire