赞
踩
matplotli工具是python语言下的画图工具,可以很好用来画散点图, 图表等。
sudo apt-get install python-matplotlib
sudo yum install python-matplotlib
sudo pip install matplotlib
import matplotlib若没有错误表示安装成功
In [9]: import matplotlib In [10]: matplotlib.__version__ Out[10]: '1.5.1'
import matplotlib.pyplot as plt radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724] plt.plot(radius, area) plt.show()
import matplotlib.pyplot as plt radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724] plt.plot(radius, area, 'o') plt.show()显示
import matplotlib.pyplot as plt radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724] plt.plot(radius, area, 'o') plt.xlabel('Radius') plt.ylabel('Area') plt.title('Area of a Circle') plt.show()显示为
import matplotlib.pyplot as plt radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724] plt.plot(radius, square, marker='o', linestyle='--', color='r') plt.xlabel('Radius') plt.ylabel('Area') plt.title('Area of a Circle') plt.show()
import matplotlib.pyplot as plt radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0] area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724] plt.plot(radius, square, 'ro--') plt.xlabel('Radius') plt.ylabel('Area') plt.title('Area of a Circle') plt.show()
Color Code | Color Displayed |
r | Red |
b | Blue |
g | Green |
c | Cyan |
m | Magenta |
y | Yellow |
k | Black |
w | White |
Marker Code> | Marker Displayed |
+ | Plus Sign |
. | Dot |
o | Circle |
* | Star |
p | Pentagon |
s | Square |
x | X Character |
D | Diamond |
h | Hexagon |
^ | Triangle |
Linestyle Code | Line style Displayed |
– | Solid Line |
— | Dashed Line |
: | Dotted Line |
-. | Dash-Dotted Line |
None | No Connecting Lines |
- import matplotlib.pyplot as plt
- radius = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
- area = [3.14159, 12.56636, 28.27431, 50.26544, 78.53975, 113.09724]
- square = [1.0, 4.0, 9.0, 16.0, 25.0, 36.0]
-
- plt.plot(radius, area, label='Circle')
- plt.plot(radius, square, marker='o', linestyle='--', color='r', label='Square')
-
- plt.xlabel('Radius/Side')
- plt.ylabel('Area')
- plt.title('Area of Shapes')
- plt.legend()
-
- plt.show()
- import numpy as np
- import matplotlib.pyplot as plt
-
- # Compute the x and y coordinates for points on sine and cosine curves
- x = np.arange(0, 3 * np.pi, 0.1)
- y_sin = np.sin(x)
- y_cos = np.cos(x)
- z_cos = y_sin + y_cos
-
- # Plot the points using matplotlib
- plt.plot(x, y_sin, 'r')
- plt.plot(x, y_cos, 'b')
- plt.plot(x, z_cos, 'g')
-
- plt.xlabel('x axis label')
- plt.ylabel('y axis label')
- plt.title('Sine and Cosine')
- plt.legend(['Sine', 'Cosine', 'Sine+Cosine'])
-
- plt.show()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。