def custom_colormap(name): """ returns one of the custom colormaps as a colormap object if input is string. If input is a colormap, simply returns the object right back. >>> type(custom_colormap('rainbow_black_violet')) <class 'mpltools.color.LinearColormap'> >>> type(custom_colormap('gist_rainbow_r')) <class 'matplotlib.colors.LinearSegmentedColormap'> >>> type(custom_colormap('Greens')) <class 'matplotlib.colors.LinearSegmentedColormap'> >>> custom_colormap('not_here') Traceback (most recent call last): Exception: Colormap not present in custom colormaps: not_here """ if isinstance(name, C.LinearSegmentedColormap): return name if name in [str(x) for x in P.colormaps()]: return P.cm.get_cmap(name) if name in CUSTOM_LINEAR_SEGMENTED_COLORMAPS: return quick_colormap(CUSTOM_LINEAR_SEGMENTED_COLORMAPS[name], name) if name in CUSTOM_CONSTRUCTED_COLORMAPS: return custom_constructed_colormaps(name) raise Exception("Colormap not present in custom colormaps: " + name)
def __init__(self, app): self.dialog = QWidget.__init__(self) self.app = app # Set up the user interface from Designer. self.ui = Ui_ranges() self.ui.setupUi(self) self.cmapList = [colormap for colormap in py.colormaps() if not colormap.endswith("_r")] self.ui.colorMap.addItems(self.cmapList) self.ui.colorMap.setCurrentIndex(60) # flags self.f_mapOpen = False self.f_spOpen = False self.f_fileOpen = False self.f_firstOpening = False self.f_cacheRecovered = False self.measParams = {} self.plotParams = {} self.plotSpPos = None self.spMapPos = None self.spVerticalBarCounter = 0 self.spWaveLimits = [] # Connect up the buttons. self.ui.squareMeas.toggled.connect(self.squareMeasClicked) self.ui.xMeasMin.valueChanged.connect(self.measRangeUpdate) self.ui.xMeasMax.valueChanged.connect(self.measRangeUpdate) self.ui.xMeasStep.valueChanged.connect(self.measRangeUpdate) self.ui.colorPlotFullscale.clicked.connect(self.colorPlotFullscale) self.ui.xPlotFullscale.clicked.connect(self.xPlotFullscale) self.ui.yPlotFullscale.clicked.connect(self.yPlotFullscale) self.ui.wavePlotFullscale.clicked.connect(self.wavePlotFullscale) self.ui.plotUpdate.clicked.connect(self.update) self.ui.selectFileButton.clicked.connect(self.selectFile) QTimer.singleShot(100, self.selectFile) # select file at start
""" Example script computing the battery size as a function of the self-sufficiency and self-consumption rates Created on Fri Mar 4 01:27:31 2016 @author: Sylvain Quoilin (JRC) """ from __future__ import division import numpy as np import pandas as pd import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D from pylab import colormaps cmaps = colormaps() from scipy.optimize import fsolve from SC_functions import fSSR # Version of the function with only r_bat as input variable (r_PV is provided as a parameter) for fsolve: def SSR_fsolve(r_bat, *param): a, r_PV, SSR = param if r_PV == 0: return r_bat else: return SSR - fSSR(r_PV, r_bat, a) # test the coefficients of the 16 parameters function: coef = [
def BenchmarkSummaryFigure(models,variables,data,figname,vcolor=None,rel_only=False): """Creates a summary figure for the benchmark results contained in the data array. Parameters ---------- models : list a list of the model names variables : list a list of the variable names data : numpy.ndarray or numpy.ma.ndarray data scores whose shape is ( len(variables), len(models) ) figname : str the full path of the output file to write vcolor : list, optional an array parallel to the variables array containing background colors for the labels to be displayed on the y-axis. """ from mpl_toolkits.axes_grid1 import make_axes_locatable # data checks assert type(models) is type(list()) assert type(variables) is type(list()) assert (type(data) is type(np .empty(1)) or type(data) is type(np.ma.empty(1))) assert data.shape[0] == len(variables) assert data.shape[1] == len(models ) assert type(figname) is type("") if vcolor is not None: assert type(vcolor) is type(list()) assert len(vcolor) == len(variables) rel_cmap = "PuOr" # define some parameters nmodels = len(models) nvariables = len(variables) maxV = max([len(v) for v in variables]) maxM = max([len(m) for m in models]) wpchar = 0.15 wpcell = 0.19 hpcell = 0.25 w = maxV*wpchar + max(4,nmodels)*wpcell if not rel_only: w += (max(4,nmodels)+1)*wpcell h = maxM*wpchar + nvariables*hpcell + 1.0 bad = 0.5 if "stoplight" not in plt.colormaps(): RegisterCustomColormaps() # plot the variable scores if rel_only: fig,ax = plt.subplots(figsize=(w,h),ncols=1,tight_layout=True) ax = [ax] else: fig,ax = plt.subplots(figsize=(w,h),ncols=2,tight_layout=True) # absolute score if not rel_only: cmap = plt.get_cmap('stoplight') cmap.set_bad('k',bad) qc = ax[0].pcolormesh(np.ma.masked_invalid(data[::-1,:]),cmap=cmap,vmin=0,vmax=1,linewidth=0) div = make_axes_locatable(ax[0]) fig.colorbar(qc, ticks=(0,0.25,0.5,0.75,1.0), format="%g", cax=div.append_axes("bottom", size="5%", pad=0.05), orientation="horizontal", label="Absolute Score") plt.tick_params(which='both', length=0) ax[0].xaxis.tick_top() ax[0].set_xticks (np.arange(nmodels )+0.5) ax[0].set_xticklabels(models,rotation=90) ax[0].set_yticks (np.arange(nvariables)+0.5) ax[0].set_yticklabels(variables[::-1]) ax[0].tick_params('both',length=0,width=0,which='major') ax[0].tick_params(axis='y',pad=10) ax[0].set_xlim(0,nmodels) ax[0].set_ylim(0,nvariables) if vcolor is not None: for i,t in enumerate(ax[0].yaxis.get_ticklabels()): t.set_backgroundcolor(vcolor[::-1][i]) # relative score i = 0 if rel_only else 1 np.seterr(invalid='ignore',under='ignore') data = np.ma.masked_invalid(data) data.data[data.mask] = 1. data = np.ma.masked_values(data,1.) mean = data.mean(axis=1) std = data.std (axis=1).clip(0.02) np.seterr(invalid='ignore',under='ignore') Z = (data-mean[:,np.newaxis])/std[:,np.newaxis] Z = np.ma.masked_invalid(Z) np.seterr(invalid='warn',under='raise') cmap = plt.get_cmap(rel_cmap) cmap.set_bad('k',bad) qc = ax[i].pcolormesh(Z[::-1],cmap=cmap,vmin=-2,vmax=2,linewidth=0) div = make_axes_locatable(ax[i]) fig.colorbar(qc, ticks=(-2,-1,0,1,2), format="%+d", cax=div.append_axes("bottom", size="5%", pad=0.05), orientation="horizontal", label="Relative Score") plt.tick_params(which='both', length=0) ax[i].xaxis.tick_top() ax[i].set_xticks(np.arange(nmodels)+0.5) ax[i].set_xticklabels(models,rotation=90) ax[i].tick_params('both',length=0,width=0,which='major') ax[i].set_yticks([]) ax[i].set_xlim(0,nmodels) ax[i].set_ylim(0,nvariables) if rel_only: ax[i].set_yticks (np.arange(nvariables)+0.5) ax[i].set_yticklabels(variables[::-1]) if vcolor is not None: for i,t in enumerate(ax[i].yaxis.get_ticklabels()): t.set_backgroundcolor(vcolor[::-1][i]) # save figure fig.savefig(figname)
pylab.axis('off') if __name__ == '__main__': dims = numpy.array([50, 50]) sesName = 'a98nm5' grpName = 'movie' chan = 1 movtregion = [10.0, 40.0] dt = 0.049584 mov = getRFMovieStm(dims, movtregion, sesName, grpName, chan) pylab.colormaps() plotMovieFrames(mov, npic=100, cmap=pylab.cm.gray, tstart=movtregion[0]) dim_t = 300 Tsim = 1.2 nTimeSteps = 300 stmframes = numpy.r_[numpy.zeros(125), numpy.ones(25), numpy.zeros(25), numpy.ones(25), numpy.zeros(25), numpy.ones(25), numpy.zeros(50)] letters = ['A', 'B', 'E']