Re: [Matplotlib-users] share axis and rotate subplot

2010-07-29 Thread Matthias Michler
On Thursday July 29 2010 12:05:24 Bala subramanian wrote:
 Friends,
 I wrote a small script to plot a data and its pdf in single figure but as
 two subplots.
 
 1) However i want to share xaxis of ax2 (subplot 122) with the y axis of
 ax1 (subplot 121). What function should i use do that. I tried sharex and
 sharey but i am not gettting what i want.
 
 2) Is there any possiblity to one of the subplot for instance i want to
 rotate ax2 by 90.
 
 #!/usr/bin/env python
 import matplotlib.pyplot as plt
 import numpy as np
 import matplotlib.mlab as mlb
 data1=np.loadtxt('test.rms',usecols=(1,))
 fig=plt.figure()
 ax1=fig.add_subplot(121)
 ax2=fig.add_subplot(122)
 ax1.plot(data1)
 mu,sigma=np.mean(data1),np.std(data1)
 n, bins, patches = ax2.hist(data1, bins=25, normed=1, facecolor='green',
 alpha=0.75,visible=False)
 y = mlb.normpdf( bins, mu, sigma)
 l = ax2.plot(bins,y,'-',linewidth=1.2)
 plt.show()

Hi Bala,

I attached a small stand-alone example, which illustrates two ways of showing 
data and its pdf sharing one axis. Maybe this can serve as a starting point 
for you to solve the problem or you can describe in more detail what is 
missing.

Kind regards,
Matthias 
import numpy as np
import matplotlib.pyplot as plt

# generate some random data
time = np.arange(1000)
data = np.random.uniform(size=1000)

# generate histogram of data
hist, bin_edges = np.histogram(data)

# 2 subplots sharing x-axis (- data values)
plt.figure(1)
ax1 = plt.subplot(211)
ax1.set_xlabel(binned data)
ax1.set_ylabel(freqency of binned data)
ax1.plot(0.5*(bin_edges[:-1]+bin_edges[1:]), hist)
ax1.set_ylim(0, max(hist))

ax2 = plt.subplot(212, sharex=ax1)
ax2.set_xlabel(data)
ax2.set_ylabel(time)
ax2.plot(data, time)

# 2 subplots sharing y-axis (- data values)
plt.figure(2)
ax3 = plt.subplot(121)
ax2.set_xlabel(time)
ax3.set_ylabel(data)
ax3.plot(time, data)
ax4 = plt.subplot(122, sharey=ax3)
ax4.set_ylabel(binned data)
ax4.set_xlabel(freqency of binned data)
ax4.plot(hist, 0.5*(bin_edges[:-1]+bin_edges[1:]))
ax4.set_xlim(0, max(hist))

plt.show()
--
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] share axis and rotate subplot

2010-07-29 Thread Benjamin Root
On Thu, Jul 29, 2010 at 10:07 AM, Matthias Michler
matthiasmich...@gmx.netwrote:

 On Thursday July 29 2010 12:05:24 Bala subramanian wrote:
  Friends,
  I wrote a small script to plot a data and its pdf in single figure but as
  two subplots.
 
  1) However i want to share xaxis of ax2 (subplot 122) with the y axis of
  ax1 (subplot 121). What function should i use do that. I tried sharex and
  sharey but i am not gettting what i want.
 
  2) Is there any possiblity to one of the subplot for instance i want to
  rotate ax2 by 90.
 
  #!/usr/bin/env python
  import matplotlib.pyplot as plt
  import numpy as np
  import matplotlib.mlab as mlb
  data1=np.loadtxt('test.rms',usecols=(1,))
  fig=plt.figure()
  ax1=fig.add_subplot(121)
  ax2=fig.add_subplot(122)
  ax1.plot(data1)
  mu,sigma=np.mean(data1),np.std(data1)
  n, bins, patches = ax2.hist(data1, bins=25, normed=1, facecolor='green',
  alpha=0.75,visible=False)
  y = mlb.normpdf( bins, mu, sigma)
  l = ax2.plot(bins,y,'-',linewidth=1.2)
  plt.show()

 Hi Bala,

 I attached a small stand-alone example, which illustrates two ways of
 showing
 data and its pdf sharing one axis. Maybe this can serve as a starting point
 for you to solve the problem or you can describe in more detail what is
 missing.

 Kind regards,
 Matthias


Actually, I think Bala is asking for something different, and I while I
think matplotlib is *capable* of doing it, I am not aware of any easy-to-use
function to do it.  Currently, you can share a pair of x axes, or a pair of
y axes.  This is fairly straight-forward because the axes object returned
from a .add_subplot() command contains both axis objects, and you can easily
pass in another axes object to the sharex or sharey keyword arguments.
Those sharex and sharey arguments assume that you mean to pair-up the x axis
of the two axes objects, or the y axis of the two axes objects.  However,
what we want here is the ability to have the x axis in one axes object to be
paired with the y axis of another axes object.  This is a completely
different, but valid, use-case and would be a useful feature to make
available (or at least, better documented).

Ben Root
--
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users