Re: [Matplotlib-users] "Ordinal must be >= 1" with SuplotHost and dates

2010-05-21 Thread Jae-Joon Lee
On Wed, May 19, 2010 at 5:47 PM, Solomon M Negusse
 wrote:
> Hello,
> I came across  problem of label rotation with autofmt_xdate() in subplothost
> too. Is there a new version with the bug fixed or a workaround to doing the
> label rotation in subplothost?
>

While this is fixed in the svn, there is no release yet.
One workaround is to turn off axisline mode.


host = SubplotHost(fig, 111)
host.toggle_axisline(False)

Note that, with this change, things like

host.axis["left"].label.set_color(drawRxByt.get_color())

won't work and you have to use the methods of original matplotlib Axes.

Regards,

-JJ

--

___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] "Ordinal must be >= 1" with SuplotHost and dates

2010-05-20 Thread Solomon M Negusse

Hello, 
I came across  problem of label rotation with autofmt_xdate() in subplothost
too. Is there a new version with the bug fixed or a workaround to doing the
label rotation in subplothost? 
Thanks,
Solomon

Jae-Joon Lee wrote:
> 
> The workarounds suggested in this thread does not work?
> To me, the ordinal thing is not actually a bug,  but you need some
> extra caution to avoid this error happening.
> 
> The issue with the label roration is a different matter though.
> 
> Regards,
> 
> -JJ
> 
> 
> On Wed, Jan 13, 2010 at 8:16 AM, Rodribat  wrote:
>>
>>
>> Hi matplotlib users!
>>
>> Did someone solve the problem of use fig.autofmt_xdate() function with
>> SubplotHost object?
>> I googled for it and I found this question only here, without solution.
>> Is
>> there a bug? Anyone knows
>> someway to solve this?
>>
>> Thank you,
>>
>> []'s
>>
>> Rodrigo Batista
>>
>>
>> David GUERINEAU wrote:
>>>
>>> Hi matplotlib_users !
>>>
>>> I'm David from Berlin, and believe I'm experiencing some problem with
>>> the
>>> SubplotHost module:
>>>
>>> I'm generating graphs from hudge databases of cpu and ethernet
>>> statistics,
>>> and I wanted to mix several graphs concerning ethernet statistics in the
>>> same figure,
>>> with time as x axis, and bytes-in, bytes-out, packets-in, packets-out
>>> and
>>> number of
>>> collisions as three different y axes, with three different scale.
>>>
>>> I took the inspiration from
>>>
>>> for the x axes and from
>>>
>>> http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes2.html
>>> for the y axes
>>>
>>> The following code is a synthetic reproduction of the problem I'm
>>> experiencing (it is also attached):
>>>
>>> from matplotlib.dates import date2num
>>> from matplotlib import pyplot
>>> from matplotlib import pylab
>>> from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
>>> from datetime import datetime
>>>
>>> dates = [ 733581.2083337, 733581.20837962965, 733581.20842592593,
>>> 733581.2084721, 733581.20851851848,
>>>       733581.20855324075, 733581.20858796302, 733581.2086342593,
>>> 733581.20866898145, 733581.20871527772]
>>> rxB = [054L, 130L, 144L, 54L, 36L, 9L, 35L, 43L, 85L, 43L]
>>> txB = [4L, 9L, 9L, 5L, 4L, 4L, 4L, 5L, 6L, 5L]
>>> rxP = [77, 228, 251, 112, 77, 42, 75, 97, 147, 91]
>>> txP = [61, 177, 188, 90, 61, 40, 64, 76, 113, 77]
>>> col = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>>
>>> ethPlot = pyplot
>>> fig = ethPlot.figure()
>>> host = SubplotHost(fig, 111)
>>>
>>> host.set_ylabel("kB/s")
>>> host.set_xlabel("Time")
>>>
>>> par1 = host.twinx()
>>> par2 = host.twinx()
>>>
>>> par1.set_ylabel("Packets/s")
>>>
>>> par2.axis["right"].set_visible(False)
>>>
>>> offset = 60, 0
>>> new_axisline = par2.get_grid_helper().new_fixed_axis
>>> par2.axis["right2"] = new_axisline(loc="right",
>>>                     axes=par2,
>>>                     offset=offset)
>>>
>>> par2.axis["right2"].label.set_visible(True)
>>> par2.axis["right2"].set_label("Collisions")
>>>
>>> par1.set_ylim(0, 6000)
>>> par2.set_ylim(0, 7000)
>>>
>>> host.axis([ dates[0], ( dates[0] + 0.041  ), -7000, 7000])
>>> par1.axis([ dates[0], ( dates[0] + 0.041  ), -1, 1])
>>> par2.axis([ dates[0], ( dates[0] + 0.041  ), -700, 700])
>>>
>>> fig.add_axes(host)
>>> ethPlot.subplots_adjust(right=0.75)
>>>
>>> drawRxByt, = host.plot_date(dates, rxB, 'g', tz=None, xdate=True,
>>> ydate=False, label="kB/s in")
>>> drawTxByt, = host.plot_date(dates, txB, 'b', tz=None, xdate=True,
>>> ydate=False, label="kB/s out")
>>> drawRxPaq, = par1.plot_date(dates, rxP, 'm', tz=None, xdate=True,
>>> ydate=False, label="packets/s in")
>>> drawTxPaq, = par1.plot_date(dates, txP, 'y', tz=None, xdate=True,
>>> ydate=False, label="packets/s out")
>>> drawColls, = par2.plot_date(dates, col, 'r', tz=None, xdate=True,
>>> ydate=False, label="collisions")
>>>
>>> fig.autofmt_xdate()
>>>
>>> host.set_xlabel("Time")
>>> host.set_ylabel("kB/s")
>>> par1.set_ylabel("Packets/s")
>>>
>>> host.legend()
>>>
>>> host.axis["left"].label.set_color(drawRxByt.get_color())
>>> host.axis["left"].label.set_color(drawTxByt.get_color())
>>> par1.axis["right"].label.set_color(drawRxPaq.get_color())
>>> par1.axis["right"].label.set_color(drawtxPaq.get_color())
>>> par2.axis["right2"].label.set_color(drawColls.get_color())
>>>
>>> ethPlot.draw()
>>> pylab.savefig( './test.png', dpi=(640/8))
>>>
>>>
>>>
>>>
>>> Maybe I do something wrong somewhere here, but other scripts that do the
>>> same for a single graphwork like a charm. So it's not a question of
>>> dataType
>>> or something. To compare with a working code, here is the first version
>>> of
>>> the fuction that does the job on single graphs without any problem :
>>>
>>> def drawEthGraph(filename, hdates, rxP, txP, rxB, txB, col):
>>>   ethPlot = pyplot
>>>   fig = ethPlot.figure()
>>>   ax = fig.add_subplot(111)
>>>   ax.plot_date(hdates, rxP, 'g', None, True, False)
>>>   ax.plot_date(hdates, txP, 'b', None, True, False)
>>>   ax.plot_date(hdates, rxB, 'g', None

Re: [Matplotlib-users] "Ordinal must be >= 1" with SuplotHost and dates

2010-01-13 Thread Jae-Joon Lee
The workarounds suggested in this thread does not work?
To me, the ordinal thing is not actually a bug,  but you need some
extra caution to avoid this error happening.

The issue with the label roration is a different matter though.

Regards,

-JJ


On Wed, Jan 13, 2010 at 8:16 AM, Rodribat  wrote:
>
>
> Hi matplotlib users!
>
> Did someone solve the problem of use fig.autofmt_xdate() function with
> SubplotHost object?
> I googled for it and I found this question only here, without solution. Is
> there a bug? Anyone knows
> someway to solve this?
>
> Thank you,
>
> []'s
>
> Rodrigo Batista
>
>
> David GUERINEAU wrote:
>>
>> Hi matplotlib_users !
>>
>> I'm David from Berlin, and believe I'm experiencing some problem with the
>> SubplotHost module:
>>
>> I'm generating graphs from hudge databases of cpu and ethernet statistics,
>> and I wanted to mix several graphs concerning ethernet statistics in the
>> same figure,
>> with time as x axis, and bytes-in, bytes-out, packets-in, packets-out and
>> number of
>> collisions as three different y axes, with three different scale.
>>
>> I took the inspiration from
>>
>> for the x axes and from
>>
>> http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes2.html
>> for the y axes
>>
>> The following code is a synthetic reproduction of the problem I'm
>> experiencing (it is also attached):
>>
>> from matplotlib.dates import date2num
>> from matplotlib import pyplot
>> from matplotlib import pylab
>> from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
>> from datetime import datetime
>>
>> dates = [ 733581.2083337, 733581.20837962965, 733581.20842592593,
>> 733581.2084721, 733581.20851851848,
>>       733581.20855324075, 733581.20858796302, 733581.2086342593,
>> 733581.20866898145, 733581.20871527772]
>> rxB = [054L, 130L, 144L, 54L, 36L, 9L, 35L, 43L, 85L, 43L]
>> txB = [4L, 9L, 9L, 5L, 4L, 4L, 4L, 5L, 6L, 5L]
>> rxP = [77, 228, 251, 112, 77, 42, 75, 97, 147, 91]
>> txP = [61, 177, 188, 90, 61, 40, 64, 76, 113, 77]
>> col = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>
>> ethPlot = pyplot
>> fig = ethPlot.figure()
>> host = SubplotHost(fig, 111)
>>
>> host.set_ylabel("kB/s")
>> host.set_xlabel("Time")
>>
>> par1 = host.twinx()
>> par2 = host.twinx()
>>
>> par1.set_ylabel("Packets/s")
>>
>> par2.axis["right"].set_visible(False)
>>
>> offset = 60, 0
>> new_axisline = par2.get_grid_helper().new_fixed_axis
>> par2.axis["right2"] = new_axisline(loc="right",
>>                     axes=par2,
>>                     offset=offset)
>>
>> par2.axis["right2"].label.set_visible(True)
>> par2.axis["right2"].set_label("Collisions")
>>
>> par1.set_ylim(0, 6000)
>> par2.set_ylim(0, 7000)
>>
>> host.axis([ dates[0], ( dates[0] + 0.041  ), -7000, 7000])
>> par1.axis([ dates[0], ( dates[0] + 0.041  ), -1, 1])
>> par2.axis([ dates[0], ( dates[0] + 0.041  ), -700, 700])
>>
>> fig.add_axes(host)
>> ethPlot.subplots_adjust(right=0.75)
>>
>> drawRxByt, = host.plot_date(dates, rxB, 'g', tz=None, xdate=True,
>> ydate=False, label="kB/s in")
>> drawTxByt, = host.plot_date(dates, txB, 'b', tz=None, xdate=True,
>> ydate=False, label="kB/s out")
>> drawRxPaq, = par1.plot_date(dates, rxP, 'm', tz=None, xdate=True,
>> ydate=False, label="packets/s in")
>> drawTxPaq, = par1.plot_date(dates, txP, 'y', tz=None, xdate=True,
>> ydate=False, label="packets/s out")
>> drawColls, = par2.plot_date(dates, col, 'r', tz=None, xdate=True,
>> ydate=False, label="collisions")
>>
>> fig.autofmt_xdate()
>>
>> host.set_xlabel("Time")
>> host.set_ylabel("kB/s")
>> par1.set_ylabel("Packets/s")
>>
>> host.legend()
>>
>> host.axis["left"].label.set_color(drawRxByt.get_color())
>> host.axis["left"].label.set_color(drawTxByt.get_color())
>> par1.axis["right"].label.set_color(drawRxPaq.get_color())
>> par1.axis["right"].label.set_color(drawtxPaq.get_color())
>> par2.axis["right2"].label.set_color(drawColls.get_color())
>>
>> ethPlot.draw()
>> pylab.savefig( './test.png', dpi=(640/8))
>>
>>
>>
>>
>> Maybe I do something wrong somewhere here, but other scripts that do the
>> same for a single graphwork like a charm. So it's not a question of
>> dataType
>> or something. To compare with a working code, here is the first version of
>> the fuction that does the job on single graphs without any problem :
>>
>> def drawEthGraph(filename, hdates, rxP, txP, rxB, txB, col):
>>   ethPlot = pyplot
>>   fig = ethPlot.figure()
>>   ax = fig.add_subplot(111)
>>   ax.plot_date(hdates, rxP, 'g', None, True, False)
>>   ax.plot_date(hdates, txP, 'b', None, True, False)
>>   ax.plot_date(hdates, rxB, 'g', None, True, False)
>>   ax.plot_date(hdates, txB, 'b', None, True, False)
>>   ax.plot_date(hdates, col, 'r', None, True, False)
>>   ax.axis([ hdates[0], ( hdates[0] + 0.042  ), -7000, 7000])
>>   ax.grid(True)
>>   fig.autofmt_xdate()
>>   pylab.savefig( filename, dpi=(640/8))
>>
>>
>> I don't think I understand the whole process of generation, but I thought
>> at
>> least at the beginnig I was having a good f

Re: [Matplotlib-users] "Ordinal must be >= 1" with SuplotHost and dates

2010-01-13 Thread Rodribat


Hi matplotlib users!

Did someone solve the problem of use fig.autofmt_xdate() function with
SubplotHost object?
I googled for it and I found this question only here, without solution. Is
there a bug? Anyone knows
someway to solve this?

Thank you,

[]'s

Rodrigo Batista


David GUERINEAU wrote:
> 
> Hi matplotlib_users !
> 
> I'm David from Berlin, and believe I'm experiencing some problem with the
> SubplotHost module:
> 
> I'm generating graphs from hudge databases of cpu and ethernet statistics,
> and I wanted to mix several graphs concerning ethernet statistics in the
> same figure,
> with time as x axis, and bytes-in, bytes-out, packets-in, packets-out and
> number of
> collisions as three different y axes, with three different scale.
> 
> I took the inspiration from
> 
> for the x axes and from
> 
> http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes2.html
> for the y axes
> 
> The following code is a synthetic reproduction of the problem I'm
> experiencing (it is also attached):
> 
> from matplotlib.dates import date2num
> from matplotlib import pyplot
> from matplotlib import pylab
> from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
> from datetime import datetime
> 
> dates = [ 733581.2083337, 733581.20837962965, 733581.20842592593,
> 733581.2084721, 733581.20851851848,
>   733581.20855324075, 733581.20858796302, 733581.2086342593,
> 733581.20866898145, 733581.20871527772]
> rxB = [054L, 130L, 144L, 54L, 36L, 9L, 35L, 43L, 85L, 43L]
> txB = [4L, 9L, 9L, 5L, 4L, 4L, 4L, 5L, 6L, 5L]
> rxP = [77, 228, 251, 112, 77, 42, 75, 97, 147, 91]
> txP = [61, 177, 188, 90, 61, 40, 64, 76, 113, 77]
> col = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
> 
> ethPlot = pyplot
> fig = ethPlot.figure()
> host = SubplotHost(fig, 111)
> 
> host.set_ylabel("kB/s")
> host.set_xlabel("Time")
> 
> par1 = host.twinx()
> par2 = host.twinx()
> 
> par1.set_ylabel("Packets/s")
> 
> par2.axis["right"].set_visible(False)
> 
> offset = 60, 0
> new_axisline = par2.get_grid_helper().new_fixed_axis
> par2.axis["right2"] = new_axisline(loc="right",
> axes=par2,
> offset=offset)
> 
> par2.axis["right2"].label.set_visible(True)
> par2.axis["right2"].set_label("Collisions")
> 
> par1.set_ylim(0, 6000)
> par2.set_ylim(0, 7000)
> 
> host.axis([ dates[0], ( dates[0] + 0.041  ), -7000, 7000])
> par1.axis([ dates[0], ( dates[0] + 0.041  ), -1, 1])
> par2.axis([ dates[0], ( dates[0] + 0.041  ), -700, 700])
> 
> fig.add_axes(host)
> ethPlot.subplots_adjust(right=0.75)
> 
> drawRxByt, = host.plot_date(dates, rxB, 'g', tz=None, xdate=True,
> ydate=False, label="kB/s in")
> drawTxByt, = host.plot_date(dates, txB, 'b', tz=None, xdate=True,
> ydate=False, label="kB/s out")
> drawRxPaq, = par1.plot_date(dates, rxP, 'm', tz=None, xdate=True,
> ydate=False, label="packets/s in")
> drawTxPaq, = par1.plot_date(dates, txP, 'y', tz=None, xdate=True,
> ydate=False, label="packets/s out")
> drawColls, = par2.plot_date(dates, col, 'r', tz=None, xdate=True,
> ydate=False, label="collisions")
> 
> fig.autofmt_xdate()
> 
> host.set_xlabel("Time")
> host.set_ylabel("kB/s")
> par1.set_ylabel("Packets/s")
> 
> host.legend()
> 
> host.axis["left"].label.set_color(drawRxByt.get_color())
> host.axis["left"].label.set_color(drawTxByt.get_color())
> par1.axis["right"].label.set_color(drawRxPaq.get_color())
> par1.axis["right"].label.set_color(drawtxPaq.get_color())
> par2.axis["right2"].label.set_color(drawColls.get_color())
> 
> ethPlot.draw()
> pylab.savefig( './test.png', dpi=(640/8))
> 
> 
> 
> 
> Maybe I do something wrong somewhere here, but other scripts that do the
> same for a single graphwork like a charm. So it's not a question of
> dataType
> or something. To compare with a working code, here is the first version of
> the fuction that does the job on single graphs without any problem :
> 
> def drawEthGraph(filename, hdates, rxP, txP, rxB, txB, col):
>   ethPlot = pyplot
>   fig = ethPlot.figure()
>   ax = fig.add_subplot(111)
>   ax.plot_date(hdates, rxP, 'g', None, True, False)
>   ax.plot_date(hdates, txP, 'b', None, True, False)
>   ax.plot_date(hdates, rxB, 'g', None, True, False)
>   ax.plot_date(hdates, txB, 'b', None, True, False)
>   ax.plot_date(hdates, col, 'r', None, True, False)
>   ax.axis([ hdates[0], ( hdates[0] + 0.042  ), -7000, 7000])
>   ax.grid(True)
>   fig.autofmt_xdate()
>   pylab.savefig( filename, dpi=(640/8))
> 
> 
> I don't think I understand the whole process of generation, but I thought
> at
> least at the beginnig I was having a good feeling with this API.
> Now I wonder how to go around this. Maybe you'll have an idea :-o
> 
> Best regards
> 
> DvD
> 
> from matplotlib.dates import date2num
> from matplotlib import pyplot 
> from matplotlib import pylab 
> from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
> from datetime import datetime
> 
> dates = [ 733581.2083337, 733581.20837962965, 733581.20842592593,
> 733581.2084721, 733581

Re: [Matplotlib-users] "Ordinal must be >= 1" with SuplotHost and dates

2009-07-02 Thread Jae-Joon Lee
I can reproduce the error with the svn version.
It seems that the problem is not SubplotHost specific, i.e., you have
same problem if you use mpl's original axes with twinx.

I think it has something to do with the axes sharing in general.
Preventing autoscale of xaxis suppress the error.

host.set_autoscalex_on(False)
par1.set_autoscalex_on(False)
par2.set_autoscalex_on(False)

But you have to manually adjust the x-limits later

par1.set_xlim(dates[0], dates[-1])

However, autofmt_xdata does not work. And I guess this is a bug in the
SubplotHost. I may take a more look later today.

Regards,

-JJ


On Sun, Jun 28, 2009 at 1:34 PM, David GUERINEAU wrote:
> Hi matplotlib_users !
>
> I'm David from Berlin, and believe I'm experiencing some problem with the
> SubplotHost module:
>
> I'm generating graphs from hudge databases of cpu and ethernet statistics,
> and I wanted to mix several graphs concerning ethernet statistics in the
> same figure,
> with time as x axis, and bytes-in, bytes-out, packets-in, packets-out and
> number of
> collisions as three different y axes, with three different scale.
>
> I took the inspiration from
>
> for the x axes and from
>
> http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes2.html
> for the y axes
>
> The following code is a synthetic reproduction of the problem I'm
> experiencing (it is also attached):
>
> from matplotlib.dates import date2num
> from matplotlib import pyplot
> from matplotlib import pylab
> from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
> from datetime import datetime
>
> dates = [ 733581.2083337, 733581.20837962965, 733581.20842592593,
> 733581.2084721, 733581.20851851848,
>       733581.20855324075, 733581.20858796302, 733581.2086342593,
> 733581.20866898145, 733581.20871527772]
> rxB = [054L, 130L, 144L, 54L, 36L, 9L, 35L, 43L, 85L, 43L]
> txB = [4L, 9L, 9L, 5L, 4L, 4L, 4L, 5L, 6L, 5L]
> rxP = [77, 228, 251, 112, 77, 42, 75, 97, 147, 91]
> txP = [61, 177, 188, 90, 61, 40, 64, 76, 113, 77]
> col = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>
> ethPlot = pyplot
> fig = ethPlot.figure()
> host = SubplotHost(fig, 111)
>
> host.set_ylabel("kB/s")
> host.set_xlabel("Time")
>
> par1 = host.twinx()
> par2 = host.twinx()
>
> par1.set_ylabel("Packets/s")
>
> par2.axis["right"].set_visible(False)
>
> offset = 60, 0
> new_axisline = par2.get_grid_helper().new_fixed_axis
> par2.axis["right2"] = new_axisline(loc="right",
>                     axes=par2,
>                     offset=offset)
>
> par2.axis["right2"].label.set_visible(True)
> par2.axis["right2"].set_label("Collisions")
>
> par1.set_ylim(0, 6000)
> par2.set_ylim(0, 7000)
>
> host.axis([ dates[0], ( dates[0] + 0.041  ), -7000, 7000])
> par1.axis([ dates[0], ( dates[0] + 0.041  ), -1, 1])
> par2.axis([ dates[0], ( dates[0] + 0.041  ), -700, 700])
>
> fig.add_axes(host)
> ethPlot.subplots_adjust(right=0.75)
>
> drawRxByt, = host.plot_date(dates, rxB, 'g', tz=None, xdate=True,
> ydate=False, label="kB/s in")
> drawTxByt, = host.plot_date(dates, txB, 'b', tz=None, xdate=True,
> ydate=False, label="kB/s out")
> drawRxPaq, = par1.plot_date(dates, rxP, 'm', tz=None, xdate=True,
> ydate=False, label="packets/s in")
> drawTxPaq, = par1.plot_date(dates, txP, 'y', tz=None, xdate=True,
> ydate=False, label="packets/s out")
> drawColls, = par2.plot_date(dates, col, 'r', tz=None, xdate=True,
> ydate=False, label="collisions")
>
> fig.autofmt_xdate()
>
> host.set_xlabel("Time")
> host.set_ylabel("kB/s")
> par1.set_ylabel("Packets/s")
>
> host.legend()
>
> host.axis["left"].label.set_color(drawRxByt.get_color())
> host.axis["left"].label.set_color(drawTxByt.get_color())
> par1.axis["right"].label.set_color(drawRxPaq.get_color())
> par1.axis["right"].label.set_color(drawtxPaq.get_color())
> par2.axis["right2"].label.set_color(drawColls.get_color())
>
> ethPlot.draw()
> pylab.savefig( './test.png', dpi=(640/8))
>
>
>
>
> Maybe I do something wrong somewhere here, but other scripts that do the
> same for a single graphwork like a charm. So it's not a question of dataType
> or something. To compare with a working code, here is the first version of
> the fuction that does the job on single graphs without any problem :
>
> def drawEthGraph(filename, hdates, rxP, txP, rxB, txB, col):
>   ethPlot = pyplot
>   fig = ethPlot.figure()
>   ax = fig.add_subplot(111)
>   ax.plot_date(hdates, rxP, 'g', None, True, False)
>   ax.plot_date(hdates, txP, 'b', None, True, False)
>   ax.plot_date(hdates, rxB, 'g', None, True, False)
>   ax.plot_date(hdates, txB, 'b', None, True, False)
>   ax.plot_date(hdates, col, 'r', None, True, False)
>   ax.axis([ hdates[0], ( hdates[0] + 0.042  ), -7000, 7000])
>   ax.grid(True)
>   fig.autofmt_xdate()
>   pylab.savefig( filename, dpi=(640/8))
>
>
> I don't think I understand the whole process of generation, but I thought at
> least at the beginnig I was having a good feeling with this API.
> Now I wonder how to go around this. Maybe you'll have an idea :-o
>
> Bes

[Matplotlib-users] "Ordinal must be >= 1" with SuplotHost and dates

2009-07-02 Thread David GUERINEAU
Hi matplotlib_users !

I'm David from Berlin, and believe I'm experiencing some problem with the
SubplotHost module:

I'm generating graphs from hudge databases of cpu and ethernet statistics,
and I wanted to mix several graphs concerning ethernet statistics in the
same figure,
with time as x axis, and bytes-in, bytes-out, packets-in, packets-out and
number of
collisions as three different y axes, with three different scale.

I took the inspiration from

for the x axes and from

http://matplotlib.sourceforge.net/examples/axes_grid/demo_parasite_axes2.html
for the y axes

The following code is a synthetic reproduction of the problem I'm
experiencing (it is also attached):

from matplotlib.dates import date2num
from matplotlib import pyplot
from matplotlib import pylab
from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
from datetime import datetime

dates = [ 733581.2083337, 733581.20837962965, 733581.20842592593,
733581.2084721, 733581.20851851848,
  733581.20855324075, 733581.20858796302, 733581.2086342593,
733581.20866898145, 733581.20871527772]
rxB = [054L, 130L, 144L, 54L, 36L, 9L, 35L, 43L, 85L, 43L]
txB = [4L, 9L, 9L, 5L, 4L, 4L, 4L, 5L, 6L, 5L]
rxP = [77, 228, 251, 112, 77, 42, 75, 97, 147, 91]
txP = [61, 177, 188, 90, 61, 40, 64, 76, 113, 77]
col = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]

ethPlot = pyplot
fig = ethPlot.figure()
host = SubplotHost(fig, 111)

host.set_ylabel("kB/s")
host.set_xlabel("Time")

par1 = host.twinx()
par2 = host.twinx()

par1.set_ylabel("Packets/s")

par2.axis["right"].set_visible(False)

offset = 60, 0
new_axisline = par2.get_grid_helper().new_fixed_axis
par2.axis["right2"] = new_axisline(loc="right",
axes=par2,
offset=offset)

par2.axis["right2"].label.set_visible(True)
par2.axis["right2"].set_label("Collisions")

par1.set_ylim(0, 6000)
par2.set_ylim(0, 7000)

host.axis([ dates[0], ( dates[0] + 0.041  ), -7000, 7000])
par1.axis([ dates[0], ( dates[0] + 0.041  ), -1, 1])
par2.axis([ dates[0], ( dates[0] + 0.041  ), -700, 700])

fig.add_axes(host)
ethPlot.subplots_adjust(right=0.75)

drawRxByt, = host.plot_date(dates, rxB, 'g', tz=None, xdate=True,
ydate=False, label="kB/s in")
drawTxByt, = host.plot_date(dates, txB, 'b', tz=None, xdate=True,
ydate=False, label="kB/s out")
drawRxPaq, = par1.plot_date(dates, rxP, 'm', tz=None, xdate=True,
ydate=False, label="packets/s in")
drawTxPaq, = par1.plot_date(dates, txP, 'y', tz=None, xdate=True,
ydate=False, label="packets/s out")
drawColls, = par2.plot_date(dates, col, 'r', tz=None, xdate=True,
ydate=False, label="collisions")

fig.autofmt_xdate()

host.set_xlabel("Time")
host.set_ylabel("kB/s")
par1.set_ylabel("Packets/s")

host.legend()

host.axis["left"].label.set_color(drawRxByt.get_color())
host.axis["left"].label.set_color(drawTxByt.get_color())
par1.axis["right"].label.set_color(drawRxPaq.get_color())
par1.axis["right"].label.set_color(drawtxPaq.get_color())
par2.axis["right2"].label.set_color(drawColls.get_color())

ethPlot.draw()
pylab.savefig( './test.png', dpi=(640/8))




Maybe I do something wrong somewhere here, but other scripts that do the
same for a single graphwork like a charm. So it's not a question of dataType
or something. To compare with a working code, here is the first version of
the fuction that does the job on single graphs without any problem :

def drawEthGraph(filename, hdates, rxP, txP, rxB, txB, col):
  ethPlot = pyplot
  fig = ethPlot.figure()
  ax = fig.add_subplot(111)
  ax.plot_date(hdates, rxP, 'g', None, True, False)
  ax.plot_date(hdates, txP, 'b', None, True, False)
  ax.plot_date(hdates, rxB, 'g', None, True, False)
  ax.plot_date(hdates, txB, 'b', None, True, False)
  ax.plot_date(hdates, col, 'r', None, True, False)
  ax.axis([ hdates[0], ( hdates[0] + 0.042  ), -7000, 7000])
  ax.grid(True)
  fig.autofmt_xdate()
  pylab.savefig( filename, dpi=(640/8))


I don't think I understand the whole process of generation, but I thought at
least at the beginnig I was having a good feeling with this API.
Now I wonder how to go around this. Maybe you'll have an idea :-o

Best regards

DvD
from matplotlib.dates import date2num
from matplotlib import pyplot 
from matplotlib import pylab 
from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
from datetime import datetime

dates = [ 733581.2083337, 733581.20837962965, 733581.20842592593, 733581.2084721, 733581.20851851848, 
	  733581.20855324075, 733581.20858796302, 733581.2086342593, 733581.20866898145, 733581.20871527772]
rxB = [054L, 130L, 144L, 54L, 36L, 9L, 35L, 43L, 85L, 43L]
txB = [4L, 9L, 9L, 5L, 4L, 4L, 4L, 5L, 6L, 5L]
rxP = [77, 228, 251, 112, 77, 42, 75, 97, 147, 91]
txP = [61, 177, 188, 90, 61, 40, 64, 76, 113, 77]
col = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]

ethPlot = pyplot
fig = ethPlot.figure()
host = SubplotHost(fig, 111)

host.set_ylabel("kB/s")
host.set_xlabel("Time")

par1 = host.twinx()
par2 = host.twinx()

par1.set_ylabel("Packets/s")

par2.axis["right"].set_visible(