plt drawing tools (two-dimensional graphics)

1. FIG linear

import numpy as np 
from matplotlib import pyplot as plt 
 
x = np.arange(1,11) 
y =  2  * x +  5 
plt.title("Matplotlib demo") 
plt.xlabel("x axis caption") 
plt.ylabel("y axis caption") 
plt.plot(x,y) 
plt.grid(True)
plt.show()
View Code

plt.grid grid lines

2. Scatter

plt.scatter(x,y,marker='o',color='r')

 

color 颜色参数 b(blue) g(grenn) r(red) c(cyan) m(magenta) y(yellow) k(boack) w(white)

marker dot graphic styles

3. Histogram

plt.bar(x, y, color='green',width=0.8)

 

The width of the width of the column

plt.barh (x, y) perpendicular to the bar graph

 

4. Pie

plt.pie([5,6,7], labels=['a','b','c'],autopct='%0.f%%',shadow=True)  

5. Multi FIG form

 

import matplotlib.pyplot as plt
import numpy as np

# Plot circle of radius 3.

an = np.linspace(0, 2 * np.pi, 100)
fig, axs = plt.subplots(2, 2)

axs[0, 0].plot(3 * np.cos(an), 3 * np.sin(an))
axs[0, 0].set_title('not equal, looks like ellipse', fontsize=10)

axs[0, 1].plot(3 * np.cos(an), 3 * np.sin(an))
axs[0, 1].axis('equal')
axs[0, 1].set_title('equal, looks like circle', fontsize=10)

axs[1, 0].plot(3 * np.cos(an), 3 * np.sin(an))
axs[1, 0].axis('equal')
axs[1, 0].set(xlim=(-3, 3), ylim=(-3, 3))
axs[1, 0].set_title('still a circle, even after changing limits', fontsize=10)

axs[1, 1].plot(3 * np.cos(an), 3 * np.sin(an))
axs[1, 1].set_aspect('equal', 'box')
axs[1, 1].set_title('still a circle, auto-adjusted data limits', fontsize=10)

fig.tight_layout()

plt.show()
View Code

 

Pro rata segmentation

Import numpy AS NP 
 Import matplotlib.pyplot AS PLT 
 # calculation points on the sine and cosine curves x and y coordinates 
x = np.arange (0, * np.pi. 3, 0.1 ) 
y_sin = np.sin (x) 
y_cos = np.cos (X)  
 # establish grid subplot, 2 height, width 1   
# activate the first subplot 
plt.subplot (2, 1, 1 )  
 # draw the first image 
plt.plot (X, y_sin) 
PLT .title ( ' the Sine ' )  
 # the second subplot activated and draw the second image 
plt.subplot (2,. 1, 2 ) 
plt.plot (X, y_cos) 
plt.title ( ' Cosine ')  
 # Show images 
plt.show ()
View Code

 

6. draw function

import matplotlib.pyplot as plt
import numpy as np

import matplotlib.mathtext as mathtext
import matplotlib

matplotlib.rc('image', origin='upper')

parser = mathtext.MathTextParser("Bitmap")

parser.to_png('test3.png',r'$ \alpha_1 \beta_j \pi \lambda \omega $',color='green', fontsize=30, dpi=100)
img = plt.imread('test3.png')  

plt.imshow(img)
plt.show()
View Code

 

Guess you like

Origin www.cnblogs.com/yangyang12138/p/12549932.html