SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: bobnojio <ste...@li...> - 2010年07月29日 15:52:47
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.
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)
-- 
View this message in context: http://old.nabble.com/Data-margin-buffer-in-matplotlib-%28Date-formatted-axis%29-tp29297756p29297756.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Eric F. <ef...@ha...> - 2010年07月30日 17:09:42
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)
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /