Data analysis and presentation-Matplotlib basic plotting function example, data analysis matplotlib
Matplotlib library entry Matplotlib basic plotting function example pyplot basic chart function Overview
| Function |
Description |
| Plt. plot (x, y, fmt ,...) |
Draw a coordinate chart |
| Plt. boxplot (data, notch, position) |
Draw a box chart |
| Plt. bar (left, height, width, bottom) |
Draw a bar chart |
| Plt. barh (width, bottom, left, height) |
Draw a horizontal bar chart |
| Plt. polar (theta, r) |
Draw a polar chart |
| Plt. pie (data, explode) |
Create a pie chart |
| Plt. pas (x, NFFT = 256, pad_to, Fs) |
Draw a power spectrum density chart |
| Plt. specgram (x, NFFT = 256, pad_to, F) |
Draw a spectrum |
| Plt. cohere (x, y, NFFT = 256, Fs) |
Draw correlation functions for X-Y |
| Plt. scatter (x, y) |
Draw a scatter chart with the same length as x and y |
| Plt. step (x, y, where) |
Draw a step chart |
| Plt. hist (x, bins, normed) |
Draw a Histogram |
| Plt. contour (X, Y, Z, N) |
Draw an equivalent Diagram |
| Plt. vlines () |
Draw a vertical chart |
| Plt. stem (x, y, linefmt, markerfmt) |
Drawing a firewood Diagram |
| Plt. plot_date () |
Draw Data Date |
Pyplot pie chart
import matplotlib.pyplot as pltlabels = 'Frogs', 'Hogs' ,'Dogs' ,'Logs'sizes = [15, 30, 45, 10]explode = (0, 0.1, 0, 0)plt.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=False,startangle=90)plt.show()
import matplotlib.pyplot as pltlabels = 'Frogs', 'Hogs' ,'Dogs' ,'Logs'sizes = [15, 30, 45, 10]explode = (0, 0.1, 0, 0)plt.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=False,startangle=90)plt.axis('equal')plt.show()
Plot the pyplot Histogram
Import numpy as npimport matplotlib. pyplot as pltnp. random. seed (0) mu, sigma = 100, 20 # mean and standard deviation a = np. random. normal (mu, sigma, size = 100) plt. hist (a, 20, normed = 1, histtype = 'stepfilled ', facecolor =' B ', alpha = 0.75) # bin: Number of histograms plt. title ('histogram ') plt. show ()
Pyplot polar chart
import numpy as npimport matplotlib.pyplot as pltN = 20theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)radii = 10 * np.random.rand(N)width = np.pi / 4 * np.random.rand(N)ax = plt.subplot(111, projection='polar')bars = ax.bar(theta, radii, width = width, bottom = 0.0)for r, bar in zip(radii, bars): bar.set_facecolor(plt.cm.viridis(r / 10.)) bar.set_alpha(0.5)plt.show()
Plot a pyplot scatter chart
import numpy as npimport matplotlib.pyplot as pltfig, ax = plt.subplots()ax.plot(10 * np.random.randn(100), 10 * np.random.randn(100), 'o')ax.set_title('Simple Scatter')plt.show()