## matplotlib-users

 Re: [Matplotlib-users] order of plotting for 'layer' of data From: Ryan Nelson - 2011-09-05 03:49:37 Attachments: Message as HTML ```Rob, Have you tried the zorder argument. It is an integer that controls the relative 'height' of a plotting element: higher numbers are plotted over lower numbers. For example, the following code plots the scatter points on top of the plotted line (even though scatter was called first): import numpy as np import matplotlib.pyplot as plt x = np.linspace(-1, 1, 10) y = np.random.rand(10) plt.scatter(x, y, s=50, zorder=2) plt.plot(x, y, 'r', lw=2, zorder=1) plt.show() Also, looking over your code, I noticed you had a for loop for your plot commands. The plot command can take two dimensional arrays for x and y as well. In this case, the x and y data for each individual plot are the columns of the 2D arrays. For your problem in particular, you may find Numpy's 'tile' command to be useful as well. Here's some code that does something similar to what you are doing (I think). import numpy as np import matplotlib.pyplot as plt z = np.tile( range(5), (5,1) ) plt.plot(z, np.random.rand(5, 5), 'o') plt.show() This may not make a big difference in your code, but if you have a lot of data, it may speed things up a little. (As I understand it, the Python for loops can be a little slow.) Hope this helps a little. Ryan Date: Fri, 02 Sep 2011 14:18:39 -0230 > From: Rob Briggs > Subject: [Matplotlib-users] order of plotting for 'layer' of data > To: matplotlib-users@... > Message-ID: <1314982119.4902.118.camel@...> > Content-Type: text/plain; charset="us-ascii" > > Hello, > > I'm not sure of the correct way to ask this question.....I'm trying to > create a plot that has a number of layers. I plot a standard plot, then > a scatterplot over that. See attachment. I expected the scatter plot to > 'render/draw' after the standard plot command, but the scatter plot data > is buried under the standard command. > > I tried changing the order, i.e. scatterplot first but that had no > effect. How do I ensure the scatterplot data is plotted above/over the > other data? > > The following code extract is after all the data has been read and > sorted. > > # start plotting > plt.close() > > # first EAIS data > stitle = 'plot showing cumulative paleoHmodel and paleoHscore for EAIS' > # set up index range for plotting > il=0 # index for lower bound to plot > iu=idx_splt # index for upper bound to plot > > fig = plt.figure(5,figsize=(18,12)) > ax1 = fig.add_subplot(111) > plt.title(stitle, fontsize=16) > plt.xlabel("paleoH data point") > plt.ylabel("thickness [m]") > > ii=np.empty(num_rows) > # plot the model results > for i in range(il,iu): > ii[:] = i+1 > plt.plot(ii,a[:,i],'o',color='0.9') > > # set axis limits > ymin=-1800 > ymin=-500 > ax1.set_xlim(il,iu+1) > top = 3000 > bottom=-500 > ax1.set_ylim(bottom, top) > > # plot the labels > for i in range(il,iu): > plt.text(i+1,ymin,datn[i], horizontalalignment='center', > fontsize=10,rotation='vertical', verticalalignment='bottom') > > > #cmap = cm.get_cmap('PRGn', 10) > #cmap = cm.get_cmap('autumn_r', 100) > #cmap = cm.get_cmap('gray', 100) > > #plt.scatter(obs[il:iu,0],obs[il:iu,1],c=time[il:iu],marker='s',s=50,cmap=cmap) > plt.scatter(obs[il:iu,0], obs[il:iu,1], c=time[il:iu],marker='s',s=100) > plt.colorbar() > > # plot the observation dp with error bars > #plt.errorbar(obs[il:iu,0], obs[il:iu,1], yerr=obs[il:iu,2], fmt='r.') > > plt.grid(which='both') > fname="scoreVSpaleoHsite.png" > plt.savefig(fname) > plt.show() > > > Regards > > Rob > > > This electronic communication is governed by the terms and conditions at > http://www.mun.ca/cc/policies/electronic_communications_disclaimer_2011.php > -------------- next part -------------- > A non-text attachment was scrubbed... > Name: scoreVSpaleoHsite.png > Type: image/png > Size: 223292 bytes > Desc: not available > > ```