x label is shifted by 1 tick

Hi,

I am trying to plot a graph as shown. http://trac-hacks.org/attachment/wiki/TracMetrixDashboard/cummulative.PNG

I am not sure why the label start at the point 1 instead of point 0. Here is the code that is used to generate the graph.

matplotlib.use(

···

‘Agg’*)
fig = figure()

ax = fig.add_subplot(

  1. Create supplot with key 111

ax.cla()

ax.plot(numdates, tkt_cummulative_table[

‘Enter’*], ‘b-’
)
ax.plot(numdates, tkt_cummulative_table[

‘Leave’*], ‘r-’
)
ax.plot(numdates, tkt_cummulative_table[

‘Finish’*], ‘g-’
)
ax.set_xlim( numdates[

0], numdates[-1] )
ax.xaxis.set_major_locator(DayLocator())

ax.xaxis.set_major_formatter( DateFormatter(

‘%Y-%m-%d’*))
ax.fmt_xdata = DateFormatter(

‘%Y-%m-%d %H:%M:%S’*)
labels = ax.get_xticklabels()

setp(labels, rotation=

45, fontsize=8)

xlabel(

‘Dates (day)’*)
ylabel(

‘Counts (times)’*)
title(

‘Cummulative flow chart for ticket status history’*)
legend((

‘Ticket Entered’, ‘Ticket Left’
, ‘Ticket Completed’), loc=
‘upper left’*
)
numdate is the array of date generated from drange function. I am pretty new to matplotlib. I create these code from looking at the examples. I might have done something wrong. If you could put it out for me, it would be very appreciated.

I am also wonder why we need ax.set_xlim( numdates[0], numdates[-1
]. However, if I don’t use it. There graph will include a few days that aren’t in the numdates in the graph.

Thanks,

Deen

Could someone help me figure out how I can move the x lebel to match
the bar chart?

Thanks,
Deen

···

On 8/19/07, Deen Sethanandha <khundeen@...287...> wrote:

Hi,

  I am trying to plot a graph as shown.
http://trac-hacks.org/attachment/wiki/TracMetrixDashboard/cummulative.PNG

  I am not sure why the label start at the point 1 instead of point 0. Here
is the code that is used to generate the graph.

matplotlib.use(*'Agg'*)

fig = figure()

ax = fig.add_subplot(111) # Create supplot with key 111

ax.cla()

ax.plot(numdates, tkt_cummulative_table[*'Enter'*], *'b-'*)

ax.plot(numdates, tkt_cummulative_table[*'Leave'*], *'r-'*)

ax.plot(numdates, tkt_cummulative_table[*'Finish'*], *'g-'*)

ax.set_xlim( numdates[0], numdates[-1] )

ax.xaxis.set_major_locator(DayLocator())

ax.xaxis.set_major_formatter( DateFormatter(*'%Y-%m-%d'*))

ax.fmt_xdata = DateFormatter(*'%Y-%m-%d %H:%M:%S'*)

labels = ax.get_xticklabels()

setp(labels, rotation=45, fontsize=8)

xlabel(*'Dates (day)'*)

ylabel(*'Counts (times)'*)

title(*'Cummulative flow chart for ticket status history'*)

legend((*'Ticket Entered'*, *'Ticket Left'*, *'Ticket Completed'*),
loc=*'upper
left'*)

numdate is the array of date generated from drange function. I am pretty
new to matplotlib. I create these code from looking at the examples. I
might have done something wrong. If you could put it out for me, it would
be very appreciated.

I am also wonder why we need ax.set_xlim( numdates[0], numdates[-1].
However,
if I don't use it. There graph will include a few days that aren't in the
numdates in the graph.

Thanks,

Deen

When using rotated ticks, if you do not set the horizontal alignment
to 'right' they will look misaligned, as in your example. Recent
versions of mpl have a figure method to rotate the ticks, move the
bottom of the subplot up to accomodate them, turn off xticks on upper
supplots, and set the horizontal alignment:

  fig.autofmt_xdate()

but you can also set the alignment manually with

setp(labels, rotation= 45, fontsize=8, horizontalalignment='right')

JDH

···

On 8/25/07, Deen Sethanandha <khundeen@...287...> wrote:

Could someone help me figure out how I can move the x lebel to match
the bar chart?