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.

I've been reading a number of links and nothing really works.
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
#

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 = fig.add_subplot(311);
   ax2 = fig.add_subplot(312, sharex=ax1);
   ax3 = fig.add_subplot(313, sharex=ax1);

   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
#!/usr/bin/python
#

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 = fig.add_subplot(311);
   ax2 = fig.add_subplot(312, sharex=ax1);
   ax3 = fig.add_subplot(313, sharex=ax1);

   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
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to