3

I made the following plot with the following code and the data is here:

enter image description here

import numpy as np
import pylab as plt
from matplotlib import rc,rcParams
rc('text',usetex=True)
rcParams.update({'font.size':10})
import matplotlib.cm as cm
from matplotlib.ticker import NullFormatter
def plot(Z_s,CWL,filter_id,spectral_type,model_mag,mag,plot_name):
      f= [r"$U_{38}$",r"$B$"  ,r"$V$"  ,r"$R$"  , r"$I$" ,r"$MB416$",r"$MB461$",r"$MB485$",r"$MB518$",r"$MB571$",r"$MB604$",r"$MB646$",r"$MB696$",r"$MB753$",r"$MB815$",r"$MB856$",r"$MB914$"]
      wavetable=CWL/(1+Z_s)
      data=model_mag-mag 
      nplist=['E', 'Sbc', 'Scd', 'Irr', 'SB3', 'SB2']
      colors = cm.rainbow(np.linspace(0, 1, len(f)))
      FILTER=filter_id
      SED=spectral_type
      for (j,d) in enumerate(nplist):
          bf=(SED==j)   
          if (j<3):
             k=j
             i_subplot = k + 1
             fig = plt.figure(1, figsize=(6,6))
             ax = fig.add_subplot(3,1,i_subplot)
             for i in range(len(f)):
                 bb=np.where(FILTER[bf]==i)[0]
                 ax.scatter(wavetable[bb], data[bb],  s=1, color=colors[i],label=f[i])
             if (k<2):
                ax.xaxis.set_major_formatter( NullFormatter() )
                ax.set_ylabel(r'$\Delta$ MAG',fontsize=10)
             else:
                ax.set_xlabel(r'WL($\AA$)',fontsize=10)
                ax.set_ylabel(r'$\Delta$ MAG',fontsize=10)
                leg = ax.legend(loc='lower center',prop={'size':4}, ncol=5)
                leg.get_frame().set_edgecolor('white')
             fig.subplots_adjust(wspace=0,hspace=0)
             ax.axhline(y=0,color='k')
             ax.set_xlim(1000,9000)
             ax.set_ylim(-3,3)
             ax.set_xticks(np.linspace(1000, 9000, 16, endpoint=False))
             ax.set_yticks(np.linspace(-3, 3, 4, endpoint=False)) 
             ax.text(8500,2.1,nplist[j], {'color': 'k', 'fontsize': 10})
             fontsize=8
             for tick in ax.xaxis.get_major_ticks():
                 tick.label1.set_fontsize(fontsize)
             for tick in ax.yaxis.get_major_ticks():
                 tick.label1.set_fontsize(fontsize)
             if (j==2):
                fname = plot_name+'.'+nplist[0]+'.'+nplist[1]+'.'+nplist[2]+'.pdf'        
                plt.savefig(fname)
                plt.close()
          else:
             k=j-3
             i_subplot = k + 1
             fig = plt.figure(1, figsize=(6,6))
             ax = fig.add_subplot(3,1,i_subplot)
             for i in range(len(f)):
                 bb=np.where(FILTER[bf]==i)[0]
                 ax.scatter(wavetable[bb], data[bb],  s=1, color=colors[i],label=f[i])
             if (k<2):
                ax.xaxis.set_major_formatter( NullFormatter() )
                ax.set_ylabel(r'$\Delta$ MAG',fontsize=10)
             else:
                ax.set_xlabel(r'WL($\AA$)',fontsize=10)
                ax.set_ylabel(r'$\Delta$ MAG',fontsize=10)
                leg = ax.legend( loc='lower center',prop={'size':4}, ncol=5)
                leg.get_frame().set_edgecolor('white')
             fig.subplots_adjust(wspace=0,hspace=0)
             ax.axhline(y=0,color='k')
             ax.set_xlim(1000,9000)
             ax.set_ylim(-3,3)
             ax.set_xticks(np.linspace(1000, 9000, 16, endpoint=False))
             ax.set_yticks(np.linspace(-3, 3, 4, endpoint=False)) 
             ax.text(8500,2.1,nplist[j], {'color': 'k', 'fontsize': 10})
             fontsize=8
             for tick in ax.xaxis.get_major_ticks():
                 tick.label1.set_fontsize(fontsize)
             for tick in ax.yaxis.get_major_ticks():
                 tick.label1.set_fontsize(fontsize)
             if (j==5):
                fname = plot_name+'.'+nplist[3]+'.'+nplist[4]+'.'+nplist[5]+'.pdf'        
                plt.savefig(fname)
                plt.close()

a=np.loadtxt('calibration.photometry.information.capak.cat')
Z_s=a[:,0]
CWL=a[:,1]
filter_id=a[:,2]
spectral_type=a[:,3]
model_mag=a[:,4]
mag=a[:,5]
plot_name='test'
plot(Z_s,CWL,filter_id,spectral_type,model_mag,mag,plot_name)

Is there anyway to change the different color legends from what I made already (in the last subplot) to a bar close to the image with the same size as whole plot? I am looking for something similar to color map for projected 3D plots in 2D which just depicts the rigid amount of legend values in my case?

Dalek
  • 4,168
  • 11
  • 48
  • 100
  • possible duplicate of [How to put the legend out of the plot](http://stackoverflow.com/questions/4700614/how-to-put-the-legend-out-of-the-plot) – Ffisegydd Sep 25 '14 at 13:18
  • In particular you want [Joe Kington's answer](http://stackoverflow.com/a/4701285/3005188) – Ffisegydd Sep 25 '14 at 13:20
  • @Ffisegydd I am looking for something similar to [this](http://rkbookreviews.files.wordpress.com/2012/04/clip_image012.jpg) – Dalek Sep 25 '14 at 13:21
  • @Ffisegydd I already saw this answer, it is not what I am looking for! – Dalek Sep 25 '14 at 13:22
  • 2
    I see. Can you make a [MCVE](http://stackoverflow.com/help/mcve) for us? At the moment it's impossible to run your code. – Ffisegydd Sep 25 '14 at 13:22
  • @Ffisegydd I want to have something similar more and less like [this](http://stackoverflow.com/questions/8342549/matplotlib-add-colorbar-to-a-sequence-of-line-plots/8363391#8363391) but I don't know how I should implement it! – Dalek Sep 25 '14 at 14:42
  • Maybe you can modify [this answer](http://stackoverflow.com/a/13784887/3100515) to do what you want by also modifying the colorbar labels? – Ajean Sep 25 '14 at 15:08
  • @Ffisegydd I updated my question, and now it gives you the same plot that I posted! – Dalek Sep 25 '14 at 17:53

0 Answers0