# Newbie help with subplots

Good morning,

I'm been using matplotlib for a while but it's always been very
simple plots (hey - I'm a simple person). I have a need for some
"fancier" plots using subplots.

I want to have 3 charts one above the other with a single set of
x-axis labels on the bottom subplot that works for all three charts.
I'd also like to put a legend outside the set of three charts - either
to the top right or horizontally along the bottom.

Most everything is around pylab and I'm using just straight
matploblib. I hate to say it, but I need to have the solution and
I'm looking for some newbie help. One of the frustrating aspects
is I need to make sure it works for version 0.91

I'm attaching a simple example script that shows the plots
as I currently have achieved them. Apologies for any bad coding.
Just in case the attachment doesn't make it through the code is
below.

Thanks!

Jeff

#!/usr/bin/python

testt.py (535 Bytes)

···

#

import matplotlib.pyplot as plt;

if __name__ == '__main__':

x=[0.0, 1.0, 2.0, 3.0, 4.0];
y1 = [11.97, 1.01, 2.97, 1.0, 1.01];
y2 = [3.55, 1.01, 3.96, 1.0, 0.0];
y3 = [0.29, 0.0, 0.0, 0.0, 0.0];

fig = plt.figure();

ax1.plot(x, y1, "ro-");
ax2.plot(x, y2, "bo-");
ax3.plot(x, y3, "go-");

ax1.grid();
ax2.grid();
ax3.grid();

plt.show();

# end main

I don’t know when it was introduced, but ax.label_outer() (called on each axes object) can help you with the axis labeling. If that works, we can then tackle legend placement.

Ben Root

···

On Fri, Feb 1, 2013 at 11:04 AM, Jeff Layton <laytonjb@…872…> wrote:

Good morning,

I’m been using matplotlib for a while but it’s always been very

simple plots (hey - I’m a simple person). I have a need for some

“fancier” plots using subplots.

I want to have 3 charts one above the other with a single set of

x-axis labels on the bottom subplot that works for all three charts.

I’d also like to put a legend outside the set of three charts - either

to the top right or horizontally along the bottom.

Most everything is around pylab and I’m using just straight

matploblib. I hate to say it, but I need to have the solution and

I’m looking for some newbie help. One of the frustrating aspects

is I need to make sure it works for version 0.91

I’m attaching a simple example script that shows the plots

as I currently have achieved them. Apologies for any bad coding.

Just in case the attachment doesn’t make it through the code is

below.

Thanks!

Jeff

2013/2/1 Benjamin Root <ben.root@…1304…>

···

On Fri, Feb 1, 2013 at 11:04 AM, Jeff Layton <laytonjb@…872…> wrote:

Good morning,

I’m been using matplotlib for a while but it’s always been very

simple plots (hey - I’m a simple person). I have a need for some

“fancier” plots using subplots.

I want to have 3 charts one above the other with a single set of

x-axis labels on the bottom subplot that works for all three charts.

I’d also like to put a legend outside the set of three charts - either

to the top right or horizontally along the bottom.

Most everything is around pylab and I’m using just straight

matploblib. I hate to say it, but I need to have the solution and

I’m looking for some newbie help. One of the frustrating aspects

is I need to make sure it works for version 0.91

I’m attaching a simple example script that shows the plots

as I currently have achieved them. Apologies for any bad coding.

Just in case the attachment doesn’t make it through the code is

below.

Thanks!

Jeff

I don’t know when it was introduced, but ax.label_outer() (called on each axes object) can help you with the axis labeling. If that works, we can then tackle legend placement.

if it does not work should be possible to do for ax1 and ax2

[t.set_visible(False) for t in ax.get_xticklabels()]

Francesco

Ben Root

Everyone hates slow websites. So do we.

Make your web apps faster with AppDynamics