scikit-spectra
scikit-spectra copied to clipboard
Remove colorbar utilitiles to separate method.
Not sure if can make one functio that will handle all plots separately, or will need a 2d/3d colorbar function. Looking at this, all I need access to are timespectra; it's dimensions, the timeunit etc...
* One goal would be to generalize the colorbar axis. So right now, it uses time and timeunit, but I think it would be useful to colorbar relative to other variables. This however would require arbitrary axis colormap first, so maybe the colormap should have an axis/orientation argument, and the colorbar would need access to that!*
Here's the code for 1D plotting for now.
if cbar:
if 'color' in pltkwargs:
raise PlotError('Colorbar requires cmap; solid color \
"%s" found.' % pltkwargs['color'])
c_rotation, c_reverse = 90, False
if cbar in ['r', 'reverse']:
c_rotation, c_reverse = 270, True
if not fig:
raise PlotError("Color bar requries access to Figure. Either pass fig"
" keyword or do not pass custom AxesSubplot.")
mappable, vmin, vmax = put._annotate_mappable(ts, pcmap, axis=0)
cbar = fig.colorbar(mappable, ticks=np.linspace(vmin, vmax, _barlabels))
tunit = getattr(ts, 'full_varunit', 'Perturbation')
cbar.set_label(r'%s$\rightarrow$' % tunit, rotation=c_rotation)
if len(ts.columns) > _barlabels -1:
label_indices = np.linspace(0, len(ts.columns), _barlabels)
label_indices = [int(round(x)) for x in label_indices]
if label_indices[-1] > len(ts.columns)-1:
label_indices[-1] = len(ts.columns)-1 #Rounds over max
labels = [ts.columns[x] for x in label_indices]
if getattr(ts, '_intervalunit', None):
if ts._interval and ts._intervalunit != 'intvl':
labels = [round(float(x),puc.float_display_units) for x in label_indices]
# Don't add custom labels if aren't at least 5 columns if DF
else:
labels = []
cbar.ax.set_yticklabels(labels)
if c_reverse:
cbar.ax.invert_yaxis()
_gencorr_2d (the correlation plot) actually does some cbar setting, consult this.