def _blank_plot(domain, ran): # make the plot fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) # thicken the axis lines ax.axhline(linewidth=1.7, color="k") ax.axvline(linewidth=1.7, color="k") x_lower, x_upper = int(domain.left), int( domain.right) # needs to be changed, is just a temporary type changer y_lower, y_upper = int(ran.left), int(ran.right) # remove tick lines on the axes plt.xticks([]) plt.yticks([]) plt.ylim(y_lower, y_upper) plt.xlim(x_lower, x_upper) # add axes labels ax.text(1.05, 0, r'$x$', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center') ax.text(0, 1.05, r'$y$', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center') # end-of-axis arrows x_width = (abs(plt.xlim()[0]) + abs(plt.xlim()[1])) y_width = (abs(plt.ylim()[0]) + abs(plt.ylim()[1])) plt.arrow(plt.xlim()[1], -0.003, 0.00000000001, 0, width=x_width * 0.0015 * 0.5, color="k", clip_on=False, head_width=y_width * 0.12 / 7, head_length=x_width * 0.024 * 0.5) plt.arrow(0.003, plt.ylim()[1], 0, 0.00000000001, width=y_width * 0.0015 * 0.5, color="k", clip_on=False, head_width=x_width * 0.12 / 7, head_length=y_width * 0.024 * 0.5) # only show cartesian axes for direction in ["xzero", "yzero"]: ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False)
def test_clipping_of_log(): # issue 804 M, L, C = Path.MOVETO, Path.LINETO, Path.CLOSEPOLY points = [(0.2, -99), (0.4, -99), (0.4, 20), (0.2, 20), (0.2, -99)] codes = [M, L, L, L, C] path = Path(points, codes) # something like this happens in plotting logarithmic histograms trans = BlendedGenericTransform(Affine2D(), LogScale.Log10Transform("clip")) tpath = trans.transform_path_non_affine(path) result = tpath.iter_segments(trans.get_affine(), clip=(0, 0, 100, 100), simplify=False) tpoints, tcodes = list(zip(*result)) assert np.allclose(tcodes, [M, L, L, L, C])
def plot_population_at(population, centers, x, y, ax=None, return_patches=False): if ax is None: _, ax = plt.subplots() data = np.array(population) spacing = (centers[1] - centers[0]) * ColorDefaults.bar_spacing label = as_plot_title(population) try: points = zip(x, y) except TypeError: points = [[x, y]] colors = sns.husl_palette(1) else: colors = sns.husl_palette(len(x)) # Show response histogram ax.set_title("Population response: {}".format(label)) ax.set_xlabel("Tuning center") ax.set_ylabel("Activity") ax.set_xlim((np.min(centers), np.max(centers))) lines = [] bars = [] for (x, y), c in zip(points, colors): patches = ax.bar(centers, data[:, x, y], width=spacing, color=c, alpha=ColorDefaults.bar_alpha, label="{x}, {y}".format(x=x, y=y)) ax.legend() # Show decoded value on x-axis z = circular_decoder(population, centers, x, y) line, = ax.plot([z], [0], color=c, marker=11, markersize=11, clip_on=False, transform=BlendedGenericTransform( ax.transData, ax.transAxes)) lines.append(line) bars.append(patches) ax.set_xticks(np.linspace(0, np.pi, 8)) ax.set_xticklabels(TICKLABELS_0_PI) if return_patches: return ax, lines, bars else: return ax
def test_clipping_of_log(): # issue 804 M, L, C = Path.MOVETO, Path.LINETO, Path.CLOSEPOLY points = [(0.2, -99), (0.4, -99), (0.4, 20), (0.2, 20), (0.2, -99)] codes = [M, L, L, L, C] path = Path(points, codes) # something like this happens in plotting logarithmic histograms trans = BlendedGenericTransform(Affine2D(), LogScale.Log10Transform('clip')) tpath = trans.transform_path_non_affine(path) result = tpath.iter_segments(trans.get_affine(), clip=(0, 0, 100, 100), simplify=False) tpoints, tcodes = list(zip(*result)) assert np.allclose(tcodes, [M, L, L, L, C])
def test_clipping_of_log(): # issue 804 M, L, C = Path.MOVETO, Path.LINETO, Path.CLOSEPOLY points = [(0.2, -99), (0.4, -99), (0.4, 20), (0.2, 20), (0.2, -99)] codes = [M, L, L, L, C] path = Path(points, codes) # something like this happens in plotting logarithmic histograms trans = BlendedGenericTransform(Affine2D(), LogScale.Log10Transform("clip")) tpath = trans.transform_path_non_affine(path) result = tpath.iter_segments(trans.get_affine(), clip=(0, 0, 100, 100), simplify=False) tpoints, tcodes = list(zip(*result)) # Because y coordinate -99 is outside the clip zone, the first # line segment is effectively removed. That means that the closepoly # operation must be replaced by a move to the first point. assert np.allclose(tcodes, [M, M, L, L, L, C])
def test_clipping_of_log(): # issue 804 M, L, C = Path.MOVETO, Path.LINETO, Path.CLOSEPOLY points = [(0.2, -99), (0.4, -99), (0.4, 20), (0.2, 20), (0.2, -99)] codes = [M, L, L, L, C] path = Path(points, codes) # something like this happens in plotting logarithmic histograms trans = BlendedGenericTransform(Affine2D(), LogScale.Log10Transform('clip')) tpath = trans.transform_path_non_affine(path) result = tpath.iter_segments(trans.get_affine(), clip=(0, 0, 100, 100), simplify=False) tpoints, tcodes = list(zip(*result)) # Because y coordinate -99 is outside the clip zone, the first # line segment is effectively removed. That means that the closepoly # operation must be replaced by a move to the first point. assert np.allclose(tcodes, [M, M, L, L, L, C])
for direction in ["xzero", "yzero"]: ax1.axis[direction].set_axisline_style("-|>") ax1.axis[direction].set_visible(True) # for direction in ["left", "right", "bottom", "top"]: ax1.axis[direction].set_visible(False) ax1.set_aspect('equal') ax1.set_xlim(-Sig_max, Sig_max) ax1.set_ylim(-Sig_max, Sig_max) ax1.text(0., 1.05, 'y', size=20, transform=BlendedGenericTransform(ax1.transData, ax1.transAxes)) ax1.text(1.05, -0.15, 'x', size=20, transform=BlendedGenericTransform(ax1.transAxes, ax1.transData)) vec_phi_xy = ax1.quiver(0, 0, 0, 0, width=10, scale=1, units='x', label=r'$\phi_n$', color='b')
import matplotlib.patches as mpatches import matplotlib.pyplot as plt import numpy as np if __name__ == '__main__': fig = plt.figure(1) ax = SubplotZero(fig, 1, 1, 1) # fig.autofmt_xdate(bottom=0.2, rotation=30, ha='right') fig.add_subplot(ax) ax.text(-1.15, 0.99, 'y', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center') ax.text(1., -0.25, 'x', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center') # for direction in ["xzero", "left"]: ax.axis[direction].set_axisline_style("-|>") ax.axis[direction].set_visible(True) for direction in ["right", "bottom", "top"]: ax.axis[direction].set_visible(False) x = np.linspace(-1., +1., 1000) # x < 0 # print(x) ax.plot(x, 3**((2*x)/(3*x+1))) plt.show()
# Espace Snn,Snt ax2 = SubplotZero(fig, 111) fig.add_subplot(ax2) # for direction in ["xzero", "yzero"]: ax2.axis[direction].set_axisline_style("-|>") ax2.axis[direction].set_visible(True) # for direction in ["left", "right", "bottom", "top"]: ax2.axis[direction].set_visible(False) ax2.set_aspect('equal') ax2.set_xlim(Sig_min, Sig_max) ax2.set_ylim(-(Sig_max-Sig_min)/2, (Sig_max-Sig_min)/2) ax2.text(0., 1.05, '$\sigma_{nt}$',size=20, transform=BlendedGenericTransform(ax2.transData, ax2.transAxes)) ax2.text(1.05, -0.15, '$\sigma_{nn}$',size=20, transform=BlendedGenericTransform(ax2.transAxes, ax2.transData)) ax2.grid() mohr_circle, = ax2.plot([], [], '.r',label='Etat de contrainte', markersize=2) ax2.legend() # ######################## def Snn_Snt_decomposition (Sigma, n) : # Check that norm of n is one n=n/np.linalg.norm(n) # Flux stress vectir phi=np.dot(Sigma,n)
from matplotlib.transforms import BlendedGenericTransform import matplotlib.pyplot as plt import numpy if 1: fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) ax.axhline(linewidth=1.7, color="black") ax.axvline(linewidth=1.7, color="black") plt.xticks(range(5)) plt.yticks(range(1,5)) ax.text(0, 1.05, '$x_{2}$', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center') ax.text(1.025, 0, '$x_{1}$', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center') for direction in ["xzero", "yzero"]: ax.axis[direction].set_axisline_style("-|>") ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False) x = numpy.linspace(-1, 3.5, 1000) y = (4 - 2*x) ax.plot(x,y) plt.annotate('$y=1$',xy=(1.75,1.5)) plt.annotate('$y=0$',xy=(0.5,1))
fig = plt.figure(1) ax = SubplotZero(fig, 1, 1, 1) fig.add_subplot(ax) labels = range(-4, 5) plt.plot(labels, labels, color="w") ax.axhline(linewidth=.7, color="black") ax.axvline(linewidth=.7, color="black") ax.text(0, 1.05, 'y', transform=BlendedGenericTransform(ax.transData, ax.transAxes), ha='center') ax.text(1.05, 0, 'x', transform=BlendedGenericTransform(ax.transAxes, ax.transData), va='center') # for direction in ["xzero", "yzero"]: ax.axis[direction].set_axisline_style("-|>") ax.axis[direction].set_visible(True) ax.set_ylim([-10, 10]) ax.set_xlim([-5, 5]) for direction in ["left", "right", "bottom", "top"]: ax.axis[direction].set_visible(False)
f, ax = plt.subplots(1, 1, figsize=fig_size) ax = sns.boxplot('estimate_name', "score", "subset", hue_order=['Dev', 'Test'], data=df_measure, order=estimate_names, showmeans=False, notch=True, showfliers=False, width=0.75, ax=ax) if measure == 'SDR': ax.set_ylim([-13.5, 15.5]) plt.setp(ax.get_xticklabels(), rotation=45, fontsize=19) lgd = ax.legend( loc='lower right', # bbox_to_anchor=(0.5, -0.22), bbox_transform=BlendedGenericTransform(f.transFigure, ax.transAxes), ncol=2) ax.set_xlabel('') ax.set_ylabel(measure + ' in dB') f.set_tight_layout(True) f.savefig(args.target + measure + ".pdf", bbox_inches='tight', dpi=300)
def plot_distributions_for_single_graph(graph_dic, fig_title, divergence=None, cdf=True, single_fig_size=(6, 4), plot_dims=None): data = analytics.create_graph_panel_from_dic(graph_dic) fig = plt.gcf() first_axes = 0 for i, feature in enumerate(data.features): for j, query in enumerate(data.queries): #if feature== 'clustering coefficient' and query == "Frontend Query": df = data.ix[:, :, query, feature].dropna(axis=1) temp_dic = {} for column in df.columns: temp_dic[column] = analytics.avg_list_of_dictionaries( df[column].tolist()) df = pnd.DataFrame.from_dict(temp_dic) #df=pnd.DataFrame.from_dict(dict([(sampler,dist) for sampler,dist in df.apply(analytics.avg_list_of_dictionaries,axis=0).iteritems()])) if plot_dims == None or plot_dims[0] * plot_dims[1] != len( data.features) * len(data.queries): #fig.set_size_inches(len(data.features)*len(data.queries)*single_fig_size[0], single_fig_size[1]) curr_axes = plt.subplot(1, len(data.features) * len(data.queries), 1 + j + len(data.queries) * i) else: curr_axes = plt.subplot(plot_dims[0], plot_dims[1], 1 + j + len(data.queries) * i) plot_distribution_for_single_query_and_feature(curr_axes, df, cdf=cdf) curr_axes.set_xlabel(feature + '(' + query + ')') curr_axes.grid(b=False, linewidth=0) if plot_dims is not None: if (1 + j + len(data.queries) * i) % plot_dims[1] == 1 or plot_dims[1] == 1: curr_axes.set_ylabel('CDF' if cdf else 'PDF') else: curr_axes.set_yticklabels([]) else: curr_axes.set_ylabel('CDF' if cdf else 'PDF') curr_axes.title.set_fontsize('small') curr_axes.tick_params(axis='both', which='major', labelsize=14) if i + j == 0: first_axes = curr_axes #################BOXPLOT################### if divergence is not None and 'Original' in data.samplers: sampler_list = list(data.ix[:, :, query, feature].columns) sampler_list.remove('Original') orig = data.ix['Original', :, query, feature] samplers = data.ix[sampler_list, :, query, feature] in_axes = plot_divergence_boxplot_as_inset_axes( divergence, cdf, curr_axes, orig, samplers) if i + j == 0: in_axes.set_title(divergence().abbreviation, fontsize='small') else: in_axes.set_yticklabels(()) sampler_list.insert(0, 'Original') ##################END BOXPLOT################ plt.draw() title = first_axes.text(0.5, 1.6, fig_title, fontsize='xx-large', ha='center', va='top', transform=BlendedGenericTransform( fig.transFigure, first_axes.transAxes)) handles, labels = curr_axes.get_legend_handles_labels() leg = fig.legend(handles, labels, ncol=3, columnspacing=1, mode='extend', fancybox=True, handlelength=3, title='Sampling Methods', borderaxespad=1, bbox_transform=BlendedGenericTransform( fig.transFigure, first_axes.transAxes), loc='upper center', fontsize='x-small', bbox_to_anchor=(0, 0.5, 1, 1)) leg.get_title().set_color("red") leg.get_frame().set_edgecolor('black') return title, leg
plt.gca().set_rgrids([.01, .0225, .035, .0475, .06], alpha=.02) #, angle=35.) # For bi-off plt.gca().set_yticklabels(['0.01%','','0.035%','',''],fontsize=10,family='serif', alpha =1) plt.gca().set_rlabel_position(20) # get radial labels away from plotted line #132.5 #plt.title('IEA37 WFLO Case Study Wind Rose', y=1.09, fontsize=20, family='serif') # Plot for X/Y axis sub2 = plt.subplot(447) sub2.spines['right'].set_visible(False) # Take off the right bar sub2.spines['top'].set_visible(False) # Take off the top bar plt.gca().set_aspect('equal', adjustable='box') # Make it an even square sub2.axhline(linewidth=1.7, color="black") sub2.axvline(linewidth=1.7, color="black") # removing the axis ticks plt.xticks([1]) plt.yticks([]) #plt.subplots_adjust(wspace=-2) sub2.text(0.1, 0.995, r'$y$', transform=BlendedGenericTransform(sub2.transData, sub2.transAxes), ha='center') sub2.text(.95, 0.1, r'$x$', transform=BlendedGenericTransform(sub2.transAxes, sub2.transData), va='center') fig = plt.gcf() arrowed_spines(fig, sub2) plt.tight_layout() # Keeps words in frame #plt.savefig('iea37-windrose.pdf',transparent=True) plt.show()
axes[0, 1].set_yticks([5]) axes[0, 1].set_yticklabels(['0'], fontsize=20) axes[0, 0].set_title("Evo", fontsize=18) axes[0, 1].set_title("Evo-Devo", fontsize=18) axes[4, 0].set_xlabel("Lifetime", fontsize=18) labels = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M"] for a in range(5): for b in range(2): axes[a, b].set_ylim([0, 10]) axes[a, b].text(1.0, -0.8, '$\mathregular{t}$', transform=BlendedGenericTransform(axes[a, b].transAxes, axes[a, b].transData), va='center', fontsize=20) axes[a, b].set_aspect('equal') axes[a, b].text(1, 8, labels[b * 5 + a], fontsize=30, fontname="Arial") # print axes[a, b].get_xlim() axes[4, 0].text(7.5, 6, "run 6", fontsize=15, ha="left", va="center") axes[4, 0].text(7.5, 2.5, "run 7$\\ast$", fontsize=15, ha="left", va="center") axes[4, 1].text(7.5, 9, "run 7", fontsize=15, ha="left", va="center") axes[4, 1].text(7.5, 3.75, "run 6$\\ast$", fontsize=15, ha="left", va="center") sns.despine() plt.tight_layout() plt.savefig("plots/Journal_Treatments.tiff", format='tiff', dpi=4500 * 0.6 / 8)