import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
N=1000
x = np.random.randn(N)
y1 = np.random.randn(N)
plt.scatter(x,y1)
plt.show()
散点图外观调整
颜色:c
透明度:alpha
点大小:s
点形状:marker
折线图
pd
import matplotlib.dates as mdates
import pandas as pd
date,open,close = pd.read_csv(r'E:\sucai\000001.csv',usecols=(0,1,4),converters = {0:mdates.strpdate2num('%m/%d/%Y')},skiprows=1)
df = pd.read_csv(r'E:\sucai\000001.csv')
df.head()
Date Open High Low Close Turnover Volume
0 1/5/2015 3258.63 3369.28 3253.88 3350.52 549760.13 53135238400
1 1/6/2015 3330.80 3394.22 3303.18 3351.45 532398.46 50166169600
2 1/7/2015 3326.65 3374.90 3312.21 3373.95 436416.70 39191888000
3 1/8/2015 3371.96 3381.57 3285.10 3293.46 399230.30 37113116800
4 1/9/2015 3276.97 3404.83 3267.51 3285.41 458648.00 41024086400
date,open,close[::]
('1/5/2015', '3258.63', '3350.52')
plt.figure(figsize=(10,6))
plt.plot_date(df['Date'],df['Open'],'-')
[<matplotlib.lines.Line2D at 0x202c4aa1e10>]
饼状图
labels = ['A','B','C','D']
fracs = [15,30,45,10]
plt.pie(x=fracs,labels=labels,autopct='%.0f%%',explode=[0,0.05,0,0])
plt.show()
fig = plt.figure()
figure实例
可以添加Axes实例
ax = fig.add_subplot(1,1,1)
返回Axes实例
参数1,子图总行数
参数2,子图总列数
参数3,子图位置
在Figure上添加Axes的常用方法
plt.grid()
调整坐标轴
axis()
例如axis([-10,10,0,10])
xlim(-5,5) ylim(-5,5)
添加坐标轴
x = np.arange(2,20,1)
y1 = x*x
y2=np.log(x)
plt.twinx()
plt.plot(x,y2,'r')
plt.plot(x,y1)
plt.show()
04-18
04-18
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交