%matplotlib inline import matplotlib.pyplot as plt import numpy as np x = np.linspace(0,np.pi,1000) f = np.sin(np.exp(x)) g = np.cos(2*x) plt.plot(x,f) plt.plot(x,g) plt.figure(figsize=(10,6), dpi=300) # changing figure's shape plt.xlim(x.min()-0.1, x.max()+0.1) # adjusting horizonatal axis limits plt.ylim(f.min()-0.1, f.max()+0.1) # adjusting vertical axis limits plt.xticks([0, np.pi/2, np.pi],[r'$-\pi$', r'$-\pi/2$', r'$0$', r'$+\pi/2$', r'$+\pi$'],fontsize=14) # setting ticks plt.yticks([-1, 0, +1],[r'$-1$', r'$0$', r'$+1$'],fontsize=14) # setting ticks plt.plot(x, f, color="blue", linewidth=2.5, linestyle="-", label="$\sin(e^x)$") # changing color and thickness plt.plot(x, g, color="red", linewidth=2.5, linestyle="-", label="$\cos(2x)$") # changing color and thickness plt.legend(loc='lower left',prop={'size':16}) # placing legend on bottom left plt.xlabel('$x$',fontsize=16) # horizontal axis name plt.ylabel('test functions',fontsize=16) # vertical axis name plt.title('Sample plot',fontsize=18) # title plt.grid(True) # enabling grid plt.savefig('trig_functions.pdf') plt.savefig? alpha = 0.7 phi_ext = 2*np.pi*0.5 def flux_qubit_potential(phi_m, phi_p): return 2 + alpha - 2*np.cos(phi_p)*np.cos(phi_m) - alpha*np.cos(phi_ext - 2*phi_p) phi_m = np.linspace(0, 2*np.pi, 100) phi_p = np.linspace(0, 2*np.pi, 100) X,Y = np.meshgrid(phi_p, phi_m) Z = flux_qubit_potential(X, Y).T from mpl_toolkits.mplot3d.axes3d import Axes3D # imports 3D plotting from matplotlib import cm # module for color pattern fig = plt.figure(figsize=(14,6)) # `ax` is a 3D-aware axis instance because of the projection='3d' keyword argument to add_subplot ax = fig.add_subplot(1, 2, 1, projection='3d') p = ax.plot_surface(X, Y, Z, rstride=4, cstride=4, linewidth=0) # surface_plot with color grading and color bar ax = fig.add_subplot(1, 2, 2, projection='3d') p = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=0, antialiased=False) cb = fig.colorbar(p, shrink=0.5) # enables colorbar # Let's generate some synthetic data data = np.random.uniform(size=(100,2)) x, y = data[:,0], data[:,1] # Let's create a fugure objec and an axes object fig1 = plt.figure(figsize=(6,6)) ax1 = fig.add_axes([0.10,0.20,0.78,0.40]) # left, bottom, width, height print dir(fig1) print dir(plt) # Don't forget to create figures and axes in the cell you are plotting! fig = plt.figure(figsize=(6,6)) ax1 = fig.add_axes([0.10,0.20,0.78,0.80]) # left, bottom, width, height # Ex: Specify a title and the axes labels ax1.scatter(x, y, marker='o') fig = plt.figure() axes1 = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # main axes axes2 = fig.add_axes([0.2, 0.5, 0.4, 0.3]) # inset axes # main figure axes1.plot(x, y, 'r.') axes1.set_xlabel('x') axes1.set_ylabel('y') axes1.set_title('title') # insert axes2.plot(y, x, 'g.') axes2.set_xlabel('y') axes2.set_ylabel('x') # Ex: add a title to the inset with a font size of 12px x = np.linspace(0,np.pi,1000) f = np.sin(8*np.exp(x)) g = np.cos(2*x) # How to enlarge a region on a plot? fig = plt.figure(figsize=(8, 6)) ax = fig.add_axes([0.15,0.11,0.83,0.83]) ax.set_xlim([0, 5]) ax.plot(x,f) ax.plot(x,g) from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes, mark_inset zoomed_inset_axes? fig = plt.figure(figsize=(8, 6)) ax = fig.add_axes([0.15,0.11,0.83,0.83]) ax.set_xlim([0, 5]) ax.plot(x,f,linewidth=0.5) ax.plot(x,g) # The inset axes axins = zoomed_inset_axes(ax, 8, loc=1) axins.plot(x, f, linewidth=1) axins.plot(x, g, linewidth=2) axins.set_xlim([2.85, 3.0]) axins.set_ylim([0.9, 1.0]) # Mark inset mark_inset(ax, axins, loc1=3, loc2=2, fc="none", ec="0") # A very quick enhancement by just importing seaborn import seaborn as sns sns.set_style("whitegrid") x = np.linspace(0,np.pi,1000) f = np.sin(np.exp(x)) g = np.cos(2*x) plt.plot(x,f) plt.plot(x,g) sns.set_style? # Bar plots sns.set_style("whitegrid") data = np.random.normal(size=(20, 6)) + np.arange(6) / 2 sns.boxplot(data); # Violing plots f, ax = plt.subplots() sns.violinplot(data) sns.despine(offset=10, trim=True); # What are the styles and how to override them? sns.axes_style() current_palette = sns.color_palette() sns.palplot(current_palette) plt.plot([0, 1], [0, 1], sns.xkcd_rgb["pale red"], lw=3) plt.plot([0, 1], [0, 2], sns.xkcd_rgb["medium green"], lw=3) plt.plot([0, 1], [0, 3], sns.xkcd_rgb["denim blue"], lw=3);