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.20833333337, 733581.20837962965, 733581.20842592593, 733581.20847222221, 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 ), -10000, 10000])
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
draw_eth_test.py (2.31 KB)