On 07/29/2010 05:52 AM, bobnojio wrote:
>
> I am trying to figure out how to set 'buffers' or something of the sort on my
> matplotlib plots, so that my first and last data points are not centered
> exactly on the left and right border of the axis.
> my Y axis does this just fine (integer data), but my X axis has no
> buffer/margin what soever.
If you are using, or can upgrade to, mpl 1.0, then you can use the
margins() Axes method or pyplot function.
Otherwise, you can use the Axes get_xlim and set_xlim methods, or the
pyplot xlim function, to manually add to the x-axis boundaries. For
example,
plot([1.1, 5.2], 'ro')
x0, x1 = xlim()
dx = 0.02 * (x1 - x0)
xlim(x0-dx, x1+dx)
Eric
>
>
> my graphing routine is as such (most fields are variables) any help is
> appreciated!:
> PlotVar.set_xlabel(xlabel)
> PlotVar.set_ylabel(ylabel)
> PlotVar.set_title(title)
> PlotVar.plot(data[xtarget][np.isfinite(data[ytarget1])],
> data[ytarget1][np.isfinite(data[ytarget1])], '-o', ms=6, lw=2, alpha=0.5,
> mfc='orange', label=label1)
> PlotVar.plot(data[xtarget][np.isfinite(data[ytarget2])],
> data[ytarget2][np.isfinite(data[ytarget2])], '-o', ms=6, lw=2, alpha=0.5,
> mfc='red', label=label2)
> PlotVar.xaxis.set_major_locator(xdays)
> PlotVar.xaxis.set_major_formatter(DateFormatter('%m-%d'))
> PlotVar.xaxis.set_minor_locator(xhours)
> PlotVar.fmt_xdata = DateFormatter('%m-%d')
> figVar.autofmt_xdate(rotation=-90, ha='left')
> highY1 =
> max(data[ytarget1][np.isfinite(data[ytarget1])])
> lowY1 =
> min(data[ytarget1][np.isfinite(data[ytarget1])])
> highY2 =
> max(data[ytarget2][np.isfinite(data[ytarget2])])
> lowY2 =
> min(data[ytarget2][np.isfinite(data[ytarget2])])
> maxvalue = max(highY1, highY2)
> minvalue = min(lowY1, lowY2)
>
> PlotVar.yaxis.set_major_locator(mticker.MultipleLocator(base=round(((maxvalue
> - minvalue)/10),3)))
>
> PlotVar.yaxis.set_minor_locator(mticker.MultipleLocator(base=round(((maxvalue
> - minvalue)/40),5)))
> plt.legend(loc='best',
> prop=matplotlib.font_manager.FontProperties(size=10))
> PlotVar.grid()
> figVar.savefig(saveto)
|