import matplotlib import matplotlib.colors as clr import matplotlib.pyplot as plt from cycler import cycler from matplotlib.colors import ListedColormap, LinearSegmentedColormap def set_size(width, fraction=1, subplots=(1, 1)): """Set figure dimensions to avoid scaling in LaTeX. Parameters ---------- width: float or string Document width in points, or string of predined document type fraction: float, optional Fraction of the width which you wish the figure to occupy subplots: array-like, optional The number of rows and columns of subplots. Returns ------- fig_dim: tuple Dimensions of figure in inches """ if width == 'thesis': width_pt = 426.79135 elif width == 'beamer': width_pt = 307.28987 else: width_pt = width # Width of figure (in pts) fig_width_pt = width_pt * fraction # Convert from pt to inches inches_per_pt = 1 / 72.27 # Golden ratio to set aesthetic figure height # https://disq.us/p/2940ij3 golden_ratio = (5**.5 - 1) / 2 # Figure width in inches fig_width_in = fig_width_pt * inches_per_pt # Figure height in inches fig_height_in = fig_width_in * golden_ratio * (subplots[0] / subplots[1]) return (fig_width_in, fig_height_in) def setRcParams(): #matplotlib.rcParams['text.usetex'] = True #matplotlib.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}' #matplotlib.rcParams['pcolor.shading'] = 'auto' matplotlib.rcParams['font.family'] = "serif" matplotlib.rcParams['font.size'] = 10 matplotlib.rcParams['axes.labelsize'] = 10 matplotlib.rcParams['legend.fontsize'] = 8 matplotlib.rcParams['xtick.labelsize'] = 8 matplotlib.rcParams['ytick.labelsize'] = 8 matplotlib.rcParams['figure.autolayout'] = True matplotlib.rcParams['figure.titlesize'] = 4 matplotlib.rcParams['axes.titlesize'] = 4 matplotlib.rcParams['lines.markersize'] = 4 # matplotlib.rcParams['axes.facecolor'] = '#e7e7e7ff' #matplotlib.rcParams['axes.grid'] = True #matplotlib.rcParams['grid.color'] = 'white' #matplotlib.rcParams['figure.dpi'] = 240 # lines for colorblind colour_blind_cycle = ['#377eb8', '#ff7f00', '#4daf4a', '#f781bf', '#a65628', '#984ea3', '#999999', '#e41a1c', '#dede00'] matplotlib.rcParams['axes.prop_cycle'] = cycler(color=colour_blind_cycle) # colorblind cmap colorblind_diverging = ['#ca0020', '#f4a582', '#f7f7f7', '#92c5de', '#0571b0'] Cmap_Name = "mymap" try: mymap = plt.get_cmap(name=Cmap_Name) except: mymap = LinearSegmentedColormap.from_list( Cmap_Name, colorblind_diverging) plt.register_cmap(name=Cmap_Name, cmap=mymap) matplotlib.rcParams['image.cmap'] = Cmap_Name