# Import modules and setup %matplotlib inline import matplotlib.pyplot as plt import numpy as np from easyplot import EasyPlot x = np.linspace(0, 10, 10) eplot = EasyPlot(x, x**2, 'g--o', label=r"$y = x^2$", showlegend=True, xlabel='x', ylabel='y', title='title', fontsize=14, markersize=10, alpha=0.6) #Note the use of plot parameter aliases and the figsize parameter eplot = EasyPlot(x, x**2, label=r"$y = x^2$", figsize=(8,4), showlegend=True, ncol=2, ms=10, ls=':', markeredgewidth=1.5, xlabel='x', ylabel='y', title='title', color='b', marker='s') eplot.add_plot(x, 0.15*x**3, label='$y = 0.15x^3$', c='c', ls='-', marker='D') #Examine set plot parameters for eplot eplot.kwargs eplot.new_plot(x, 1/(1+x), '-s', label=r"$y = \frac{1}{1+x}$", c='#fdb462') # Note that the plot reuses the axis labels, title and marker # formatting from the previous eplot template eplot.new_plot(x, 1/(1+x), '-s', label=r"$y = \frac{1}{1+x}$", c='#fdb462', grid='on') eplot.new_plot(x, 1/(1+x), '-s', label=r"$y = \frac{1}{1+x}$", c='#fdb462') eplot.grid(which='major', axis='x', linewidth=2, linestyle='--', color='b', alpha=0.5) eplot.grid(which='major', axis='y', linewidth=2, linestyle='-', color='0.85', alpha=0.5) eplot.new_plot(x, 1/(1+x), '-s', label=r"$y = \frac{1}{1+x}$", c='#fdb462', yscale='log') eplot.grid(which='minor', axis='both') # Setup colors = ["#66c2a5","#fc8d62","#8da0cb","#e78ac3","#a6d854","#ffd92f","#e5c494","#b3b3b3"] x = np.linspace(0,10,200) # Demo of color cycle # Note the use of EasyPlot constructor with no x,y data to initialize colorcycle prior to # adding plots to the figure sinplot = EasyPlot(xlabel=r'$\sin (3\pi x/L)$', ylabel='$Amplitude$', fontsize=16, colorcycle=colors, figsize=(10,5), linewidth=3) for index in range(8): sinplot.add_plot(x, np.sin(3*np.pi*x/10 + index*np.pi/7)) # Setup the x, y data and plot parameters for both modes x = np.linspace(0, 10, 11) dict_keys = ['x2', 'x3', 'x4'] labels_list = ['$y = x^2$', '$y = 0.1x^3$', '$y = 0.01x^4$'] markers_list = ['s', 'o', 'D'] linestyle_list = ['-', '--', ':'] y_dict, marker_dict, labels_dict, linestyle_dict = {}, {}, {}, {} x_list, y_list = [], [] # List of x and y data sets for mode='array' # Populate dict and list variables with data set for ind, key in enumerate(dict_keys): marker_dict[key] = markers_list[ind] labels_dict[key] = labels_list[ind] linestyle_dict[key] = linestyle_list[ind] y_dict[key] = (0.1**ind)*x**(ind+2) y_list.append((0.1**ind)*x**(ind+2)) x_list.append(x) # Demonstrate iter_plot using mode='dict' eplot = EasyPlot(xlabel=r'$x$', ylabel='$y$', fontsize=16, colorcycle=["#66c2a5","#fc8d62","#8da0cb"], figsize=(8,5)) eplot.iter_plot(x, y_dict, linestyle=linestyle_dict, marker=marker_dict, label=labels_dict, linewidth=3, ms=10, showlegend=True, grid='on') # Demonstrate iter_plot using mode='array'. Both x_list and y_list are 2D arrays eplot = EasyPlot(xlabel=r'$x$', ylabel='$y$', fontsize=16, colorcycle=["#66c2a5","#fc8d62","#8da0cb"], figsize=(8,5)) eplot.iter_plot(x_list, y_list, mode='array', linestyle=linestyle_list, marker=markers_list, label=labels_list, linewidth=3, ms=10, showlegend=True, grid='on') # Reuses sinplot template from one of the previous examples for labels, linewidth and fontsize x = np.linspace(0, 10, 200) fig, axes = plt.subplots(2, 1, figsize=(10,6)) # Create fig and axes for subplots externally # Supply fig and axes instance to EasyPlot object sinplot.new_plot(x, np.sin(3*np.pi*x/10 + np.pi/8), fig=fig, ax=axes[0], color="#fc8d62") sinplot.new_plot(x, np.sin(3*np.pi*x/10 + 9*np.pi/8), fig=fig, ax=axes[1], color="#66c2a5") fig.set_tight_layout(True) # Another example fig, axes = plt.subplots(figsize=(9,9), nrows=2, ncols=2) # Create fig and axes # Setup EasyPlot object with common plot parameters eplot = EasyPlot(xlabel='x', ylabel='y(x)', title='Plot title', fs=14, lw=3) # Loop through subplot axes and use eplot template to create new plots for (x_ind,y_ind), ax in np.ndenumerate(axes): eplot.new_plot(x, x**(x_ind+y_ind-1), fig=fig, ax=ax, c="#8da0cb") fig.tight_layout() # Setup EasyPlot object with common plot parameters x = np.linspace(0, 10, 11) eplot = EasyPlot(x, x**2, xlabel='x', ylabel='y(x)', figsize=(6,5), title='Plot title', fs=14, lw=3, xlim=(0,11), c="#fc8d62") ax = eplot.get_axes() # Modify plot by direct manipulation of axes instance ax.bar(x, x**2, align="center", width=0.5, alpha=0.6, color="#a6d854") ax.set_xticks([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) ax.set_xticklabels([r'$\alpha$', r'$\beta$', r'$\gamma$', r'$\delta$', r'$\epsilon$', r'$\chi$', r'$\nu$', r'$\mu$', r'$\omega$', r'$\phi$'], fontsize=18) eplot.redraw() # Update plot canvas with axes modifications