test_a_colormap.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. # B a r a K u d a
  3. #
  4. # L. Brodeau, 2017
  5. #
  6. import sys
  7. import numpy as nmp
  8. import matplotlib as mpl
  9. mpl.use('Agg')
  10. import matplotlib.pyplot as plt
  11. import matplotlib.colors as mplc
  12. import barakuda_colmap as bcm
  13. narg = len(sys.argv)
  14. if narg < 3:
  15. print 'Usage: '+sys.argv[0]+' <Colormap> <Min val> <Max val> <increment>'
  16. print ' ex: $ test_a_colormap.py rainbow -10 50 5'
  17. print ' $ test_a_colormap.py ncview_nrl 0 20 1'
  18. sys.exit(0)
  19. cpal_fld = sys.argv[1]
  20. tmin = float(sys.argv[2])
  21. tmax = float(sys.argv[3])
  22. rdt = float(sys.argv[4])
  23. vc_fld = nmp.arange(tmin, tmax + rdt, rdt)
  24. #for cpal_fld in bcm.list_cmap_barakuda :
  25. for cpal_fld in [ cpal_fld ] :
  26. cpal_fld = cpal_fld
  27. cfig = 'show_colmap_'+cpal_fld+'.png'
  28. pal_fld = bcm.chose_colmap(cpal_fld)
  29. nrm_fld = mplc.Normalize(vmin = tmin, vmax = tmax, clip = False)
  30. fig = plt.figure(num = 1, figsize=(10,2), dpi=None, facecolor='w', edgecolor='k')
  31. ax = plt.axes([0.01, 0.12, 0.98, 0.8])
  32. clb = mpl.colorbar.ColorbarBase(ax, ticks=vc_fld, cmap=pal_fld, norm=nrm_fld,
  33. orientation='horizontal', extend='both')
  34. plt.savefig(cfig, dpi=120, orientation='portrait', transparent=False)
  35. plt.close(1)
  36. print '\n Check how "'+cpal_fld+'" looks like in: '+cfig+' !\n'
  37. #cb_labs = [] ; cpt = 0
  38. #for rr in vc_fld:
  39. # if cpt % cb_jump == 0:
  40. # cb_labs.append(str(int(rr)))
  41. # else:
  42. # cb_labs.append(' ')
  43. # cpt = cpt + 1
  44. #clb.ax.set_xticklabels(cb_labs)
  45. #clb.set_label(cunit, **cfont_clb)