silikoniwant.blogg.se

Datacamp scatter plot matplotlib
Datacamp scatter plot matplotlib













datacamp scatter plot matplotlib

> plt.savefig('foo.png', transparent=True)Ĭlose & Clear > plt.cla() > plt.clf() > plt.Python-for-Datascience: Datacamp Introduction:Ĭheck the type of variables using type(vars)įloat – real numbers with both whole and fractional components for a number Pseudocolor plot of 2D array Pseudocolor plot of 2D array Plot contours Plot filled contours Label a contour plot Workflow The basic steps to creating plots with matplotlib are: Plt.plot(x,y,linewidth=4.0) plt.plot(x,y,ls='solid') plt.plot(x,y,ls='-') plt.plot(x,y,'-',x**2,y**2,'-.') plt.setp(lines,color='r',linewidth=4.0)ġ Prepare data 2 Create plot 3 Plot 4 Customize plot 5 Save plot 6 Show plot Plotting Routines lines = ax.plot(x,y) ax.scatter(x,y) axes.bar(,) axes.barh(,) axes.axhline(0.45) axes.axvline(0.65) ax.fill(x,y,color='blue') ax.fill_between(x,y,color='yellow')Īdd padding to a plot Set the aspect ratio of the plot to 1 Set limits for x-and y-axis Set limits for x-axis Vector Fields Draw points with lines or markers connecting them Draw unconnected points, scaled or colored Plot vertical rectangles (constant width) Plot horiontal rectangles (constant height) Draw a horizontal line across axes Draw a vertical line across axes Draw filled polygons Fill between y-values and 0 > _visible(False) Make the top axis line for a plot invisible > _position(('outward',10)) Move the bottom axis line outwardĭata Distributions > ax1.hist(y) > ax3.boxplot(y) > ax3.violinplot(z) Plot a histogram Make a box and whisker plot Make a violin plotĢD Data or Images > fig, ax = plt.subplots() > im = ax.imshow(img, cmap='gist_earth', interpolation='nearest', vmin=-2, vmax=2)Īxes2.pcolor(data2) axes2.pcolormesh(data) CS = plt.contour(Y,X,U) ntourf(data1) axes2= ax.clabel(CS) > axes.arrow(0,0,0.5,0.5) > axes.quiver(y,z) > axes.streamplot(X,Y,U,V)Īdd an arrow to the axes Plot a 2D field of arrows Plot 2D vector fields Text & Annotations > ax.text(1, -2.1, 'Example Graph', style='italic') > ax.annotate("Sine", xy=(8, 0), xycoords='data', xytext=(10.5, 0), textcoords='data', arrowprops=dict(arrowstyle="->", connectionstyle="arc3"),) > ax.t(ticks=range(1,5), ticklabels=) > ax.tick_params(axis='y', direction='inout', length=10) > ax.set(title='An Example Axes', ylabel='Y-Axis', xlabel='X-Axis') > ax.legend(loc='best') Limits, Legends & Layouts Limits & Autoscaling Plt.plot(x, x, x, x**2, x, x**3) ax.plot(x, y, alpha = 0.4) ax.plot(x, y, c='k') fig.colorbar(im, orientation='horizontal') im = ax.imshow(img, cmap='seismic') Import matplotlib.pyplot as plt x = Step 1 y = fig = plt.figure() Step 2 ax = fig.add_subplot(111) Step 3 ax.plot(x, y, color='lightblue', linewidth=3) Step 3, 4 ax.scatter(,, color='darkgreen', marker='^') > ax.set_xlim(1, 6.5) > plt.savefig('foo.png') Step 6 > plt.show() In most cases, a subplot will fit your needs. Import numpy as np x = np.linspace(0, 10, 100) y = np.cos(x) z = np.sin(x)ĢD Data or Images >ĭata = 2 * np.random.random((10, 10)) data2 = 3 * np.random.random((10, 10)) Y, X = np.mgrid U = -1 - X**2 + Y V = 1 + X - Y**2 from matplotlib.cbook import get_sample_data img = np.load(get_sample_data('axes_grid/bivariate_normal.npy'))įigure > fig = plt.figure() > fig2 = plt.figure(figsize=plt.figaspect(2.0))Īxes All plotting is done with respect to an Axes. Matplotlib is a Python 2D plotting library which produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms. Plot Anatomy & Workflow Plot Anatomy Axes/Subplot Python For Data Science Cheat Sheet Matplotlib















Datacamp scatter plot matplotlib