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

Reply via email to