--
You received this message because you are subscribed to the Google
Groups "Py-ART Users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to pyart-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Martin,
From some investigation matplotlib does not appear to be able to
show a non-linear colormap with a non-linear colorbar natively.
Plotting a pcolormesh using a non-linear colormap is typically not
too much work but is a bit difficult since Py-ART's Radardisplay
class does not pass the norm parameter to the pcolormesh calls.
Rather the colormap must be made non-linear. If you plot the
colorbar as if it corresponds to categorical data then the results
are similar to a non-linear colorbar but are segmented.
Below is a script that is my best attempt at a non-linear colormap
and colorbar using one of the Py-ART examples:
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import pyart
import numpy as np
# create a non-linear colormap
cbar_limits = [0.0, 0.4, 0.5, 0.6, 0.7, 0.8, 0.85, 0.9,
0.93, 0.95, 0.96, 0.97, 0.98, 0.99, 0.994, 0.998, 1]
nlimits = len(cbar_limits)
ref_cmap = plt.get_cmap('jet', nlimits)
segmentdata = colors.LinearSegmentedColormap.from_list(
'test', ref_cmap(np.linspace(0, 1, nlimits)))._segmentdata
cdict = {'red': [], 'green': [], 'blue': []}
for i, j in enumerate(cbar_limits):
mn, mx = segmentdata['red'][i][1:]
red_tuple = (j, mn, mx)
cdict['red'].append(red_tuple)
mn, mx = segmentdata['green'][i][1:]
green_tuple = (j, mn, mx)
cdict['green'].append(green_tuple)
mn, mx = segmentdata['blue'][i][1:]
blue_tuple = (j, mn, mx)
cdict['blue'].append(blue_tuple)
nonlin_cmap = colors.LinearSegmentedColormap('nonlinear', cdict)
# plot the data
filename = '110635.mdv'
radar = pyart.io.read_mdv(filename)
display = pyart.graph.RadarDisplay(radar)
fig = plt.figure()
ax = fig.add_subplot(111)
display.plot('normalized_coherent_power', 0, vmin=0, vmax=1.0,
colorbar_flag=False, title_flag=False,
axislabels_flag=False, cmap=nonlin_cmap)
# plot the colorbar as if it was categorical to trick matplotlib to
use uniform
# spacing between colors
fig.colorbar(
display.plots[-1], orientation='vertical', spacing='uniform',
boundaries=cbar_limits+[1.1], values=cbar_limits,
ticks=cbar_limits)
display.set_limits(ylim=[-120, 120], xlim=[-120, 120])
plt.show()
Cheers,
- Jonathan Helmus