Hello, I'm using python 2.4 and matplotlib 0.83 with WXAgg. I'm having
trouble with plot dates and the datelocator. I want to show only 5 dates
tick labels because anymore than this then the labels get crunched
together. I can get this to work with the multiplelocator but not the
datelocator. I copied the function I call to manage all my plot
attributes below. I input the canvas figure, two axes instances (axesA,
and axesD) and a class called myAxes which holds attributes like label
size and font and colors and such. I am trying to do something like this
(this is part of the code copied below):
elif myAxes.majorFormatName == 'Dates':
min, max = Numeric.array(axesA.get_xlim())
xFormat = DateFormatter('%m/%d/%y')
xmajorLocator = DateLocator((max-min)/8.0)
# set major x tick format
axesD.xaxis.set_major_formatter(xFormat)
# set major x tick format
axesA.xaxis.set_major_formatter(xFormat)
if myAxes.autoScale == False:
# set major locator
axesD.xaxis.set_major_locator(xmajorLocator)
# set major locator
axesA.xaxis.set_major_locator(xmajorLocator)
Notice I have to be aware of whether or not autoScale is being used. I
am not sure about this either. Can I set the locator and use auoscale? I
was having some errors occur when I tried to do this. The way it shows
above seems to solve that problem.
Does anyone know what might be the problem with the datelocator() as
I've done it?
Thanks!
Jeff
# redraw figure attributes
def Plot_Figure_Attributes(figure, myAxes, axesD, axesA):
# set where to tick
axesA.yaxis.tick_left()
axesD.yaxis.tick_left()
axesA.xaxis.tick_bottom()
axesD.xaxis.tick_bottom()
# turn axes on or off
if myAxes.ShowAxesFrame == True:
axesD.set_frame_on(True)
axesA.set_frame_on(True)
else:
axesD.set_frame_on(False)
axesA.set_frame_on(False)
# set range limits
if myAxes.autoScale == False:
axesA.set_xlim((myAxes.xRangeMin, myAxes.xRangeMax))
axesD.set_xlim((myAxes.xRangeMin, myAxes.xRangeMax))
axesA.set_ylim((myAxes.yRangeMinA, myAxes.yRangeMaxA))
axesD.set_ylim((myAxes.yRangeMinD, myAxes.yRangeMaxD))
else:
axesA.autoscale_view()
axesD.set_xlim(axesA.get_xlim())
# set figure background color
axesA.set_axis_bgcolor(myAxes.edgeColor)
axesD.set_axis_bgcolor(myAxes.edgeColor)
# set figure face color
figure.set_facecolor(myAxes.figureColor)
# set legend
if myAxes.legendShow == True:
#get all instances of lines created by Plot()
lines = axesA.get_lines()
#create the legend
figure.legend(lines,
myAxes.labels,
'upper right')
# set grid
if myAxes.gridShow == True:
axesD.grid(True)
axesA.grid(True)
if myAxes.yLabelShow == True:
# set figure y label
axesD.set_ylabel(myAxes.yLabelD, color=myAxes.yLabelColor,
size=myAxes.yLabelSize, rotation=myAxes.yLabelRot)
# set figure y label
axesA.set_ylabel(myAxes.yLabelA, color=myAxes.yLabelColor,
size=myAxes.yLabelSize, rotation=myAxes.yLabelRot)
if myAxes.xLabelShow == True:
# set figure x label
axesD.set_xlabel(myAxes.xLabelD, color=myAxes.xLabelColor,
size=myAxes.xLabelSize, rotation=myAxes.xLabelRot)
if myAxes.titleShow == True:
# set figure title
axesA.set_title(myAxes.title, color = myAxes.titleColor, size =
myAxes.titleSize)
(min, max) = axesA.get_ylim()
# define major y tick locator
ymajorLocator = MultipleLocator((max-min)/myAxes.yMajorTickLoc)
# define minor y tick locator
yminorLocator = MultipleLocator((max-min)/myAxes.yMinorTickLoc)
# define major y tick format
yFormat = FormatStrFormatter(myAxes.yLabelPrecision)
# define minor x formats and locators
if myAxes.majorFormatName == 'Multiples':
(min, max) = axesA.get_xlim()
if (max-min)/myAxes.xMinorTickLoc < 1:
xmajorLocator = 1
else:
xmajorLocator = (max-min)/5.0
xmajorLocator = MultipleLocator(xmajorLocator)
xFormat = FormatStrFormatter('%d')
elif myAxes.majorFormatName == 'Seconds':
xmajorLocator = SecondLocator()
xFormat = DateFormatter('%S')
elif myAxes.majorFormatName == 'Dates':
min, max = Numeric.array(axesA.get_xlim())
xFormat = DateFormatter('%m/%d/%y')
xmajorLocator = DateLocator((max-min)/8.0)
elif myAxes.majorFormatName == 'Minutes':
xmajorLocator = MinuteLocator()
xFormat = DateFormatter('%M')
elif myAxes.majorFormatName == 'Hours':
xmajorLocator = HourLocator()
xFormat = DateFormatter('%H')
elif myAxes.majorFormatName == 'Days':
xmajorLocator = DayLocator()
xFormat = DateFormatter('%m/%d/%y')
elif myAxes.majorFormatName == 'Months':
xmajorLocator = MonthLocator()
xFormat = DateFormatter('%m/%d/%y')
elif myAxes.majorFormatName == 'Years':
xmajorLocator = YearLocator()
xFormat = DateFormatter('%m/%d/%y')
# set major x tick format
axesD.xaxis.set_major_formatter(xFormat)
# set major x tick format
axesA.xaxis.set_major_formatter(xFormat)
if myAxes.autoScale == False:
# set major locator
axesD.xaxis.set_major_locator(xmajorLocator)
# set major locator
axesA.xaxis.set_major_locator(xmajorLocator)
# set x and y tick labels attributes
setAttr(axesA.get_yticklabels(),
fontsize=myAxes.yTickLabelSize,visible=True)
setAttr(axesD.get_yticklabels(),
fontsize=myAxes.yTickLabelSize,visible=True)
setAttr(axesA.get_xticklabels(),
fontsize=myAxes.xTickLabelSize,visible=True)
setAttr(axesD.get_xticklabels(),
fontsize=myAxes.xTickLabelSize,visible=True)