From: Marston <she...@gm...> - 2012-03-31 17:26:09
|
Hi, I'm trying to create a plot, with subplots where each row of x plots have a common colorbar beneath it. Only the the top row will have titles. I've tried creating a function to do this but I only achieve partial success. Here is an image created in another program that I want to duplicate: http://old.nabble.com/file/p33544950/fig.jpeg I made several functions to do this. Here's one of them: def Plot(self,title,plist): for k in np.sort(self.vdic.keys()): plt.subplot(5,13,self.window) cs = plt.contourf(22,22,np.squeeze(self.vdic[k]),plist['levels'], cmap=cm.get_cmap('jet',len(plist['levels'])-1)) plt.axis('off') if title: plt.title(k,fontsize=tsize) window += 1 cbar = plt.colorbar(cax=plist['cax'],orientation='h') I've given up in getting the text on the left because every attempt using text fails. Now if this is a horrible way and you have a better idea, please feel free to share. I'm new at matplotlib and this is a great way to see how things can be done better and in different ways. -- View this message in context: http://old.nabble.com/Subplot-array-and-colorbar-tp33544950p33544950.html Sent from the matplotlib - users mailing list archive at Nabble.com. |
From: Eric F. <ef...@ha...> - 2012-04-01 19:48:10
|
On 03/31/2012 07:26 AM, Marston wrote: > Hi, I'm trying to create a plot, with subplots where each row of x plots > have a common colorbar beneath it. Only the the top row will have > titles. I've tried creating a function to do this but I only achieve > partial success. Here is an image created in another program that I want > to duplicate: I made several functions to do this. Here's one of them: > def Plot(self,title,plist): for k in np.sort(self.vdic.keys()): > plt.subplot(5,13,self.window) cs = > plt.contourf(22,22,np.squeeze(self.vdic[k]),plist['levels'], > cmap=cm.get_cmap('jet',len(plist['levels'])-1)) plt.axis('off') if > title: plt.title(k,fontsize=tsize) window += 1 cbar = > plt.colorbar(cax=plist['cax'],orientation='h') I've given up in getting > the text on the left because every attempt using text fails. Now if this > is a horrible way and you have a better idea, please feel free to share. > I'm new at matplotlib and this is a great way to see how things can be > done better and in different ways. The problem is that what you are trying to do is a bit too complicated for the basic pyplot interface and for subplots. The axes_grid toolkit might be helpful, or you may want to calculate the axes positions yourself as in http://matplotlib.sourceforge.net/examples/pylab_examples/multi_image.html. For your text on the left, you can add text to a figure using the same coordinates as you use for specifying axes positions: (0,0) is lower left, (1,1) is upper right. E.g., in "ipython --pylab", fig = plt.figure() ax = fig.add_axes([0.4, 0.45, 0.5, 0.1]) lableft = fig.text(0.1, 0.5, "A Label") plt.draw() #needed only when interactive Eric > ------------------------------------------------------------------------ > View this message in context: Subplot array and colorbar > <http://old.nabble.com/Subplot-array-and-colorbar-tp33544950p33544950.html> > Sent from the matplotlib - users mailing list archive > <http://old.nabble.com/matplotlib---users-f2906.html> at Nabble.com. > > > > ------------------------------------------------------------------------------ > This SF email is sponsosred by: > Try Windows Azure free for 90 days Click Here > http://p.sf.net/sfu/sfd2d-msazure > > > > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |
From: Marston <she...@gm...> - 2012-04-05 08:40:05
|
I solved this problem using pyplot and the following code: x = np.arange(22) y = x window = 1 tsize = 8 plt.clf() plt.cla() nrow = 0 for k in np.sort(dlist.keys()): # 2d data arrays of size (x,y) if not doplot[k]: continue vdic = dlist[k] for v in np.sort(vdic.keys()): plt.subplot(self.rows,self.cols,window) if vlist[k] == 'RR': plt.title(v,fontsize=tsize) plt.subplots_adjust(bottom=0.26,left=0.18, # These values are taken from the GUI right=.90, top=0.94, # window after I adjusted the fig to my liking wspace=0.07,hspace=0.94) cs = plt.contourf(x,y,vdic[v],levels[k],cmap= cm.get_cmap('jet',len(levels[k])-1)) plt.axis('off') window += 1 ax = plt.gca() pos = ax.get_position() l,b,w,h = pos.bounds print l,b,w,h cax = plt.axes([l-0.668,b-0.02,0.719,0.01]) # setup colorbar axes cbar = plt.colorbar(cs,cax=cax,orientation='horizontal') cl = plt.getp(cbar.ax, 'xticklabels') plt.setp(cl, fontsize=8) fx = 0.07 fy = 0.9 dy = 0.15 yp = fy - (dy*nrow) plt.figtext(fx,yp,units[k],fontsize=tsize+1) nrow += 1 #pdb.set_trace() # debugging python -m file.py cmd = '%s%s%s' % ('ece3_',win,'_L91.pdf') plt.savefig(cmd,dpi=600,orientation='landscape') I also attached an example. Marston wrote: > > Hi, > > I'm trying to create a plot, with subplots where each row of x plots have > a common colorbar beneath it. Only the the top row will have titles. I've > tried creating a function to do this but I only achieve partial success. > Here is an image created in another program that I want to duplicate: > > http://old.nabble.com/file/p33544950/fig.jpg fig.jpg > > I made several functions to do this. Here's one of them: > > def Plot(self,title,plist): > for k in np.sort(self.vdic.keys()): > plt.subplot(5,13,self.window) > cs = plt.contourf(22,22,np.squeeze(self.vdic[k]),plist['levels'], > cmap=cm.get_cmap('jet',len(plist['levels'])-1)) > plt.axis('off') > if title: plt.title(k,fontsize=tsize) > window += 1 > cbar = plt.colorbar(cax=plist['cax'],orientation='h') > > I've given up in getting the text on the left because every attempt using > text fails. > Now if this is a horrible way and you have a better idea, please feel free > to share. > I'm new at matplotlib and this is a great way to see how things can be > done better > and in different ways. > -- View this message in context: http://old.nabble.com/Subplot-array-and-colorbar-tp33544950p33568733.html Sent from the matplotlib - users mailing list archive at Nabble.com. |