1. 折线图
matplotlib.pyplot.plot()
# 主要参数:
x,y -- 接收array,表示X轴和Y轴对应的数据,无默认
color -- 接收特定string,指定线条的颜色,默认为None
linestyle -- 接收特定string,指定线条的类型,默认为“-”
marker -- 接收特定string,表示绘制的点的类型,默认为None
alpha -- 接收0~1的小数,表示点的透明度,默认为None
# color参数的常用颜色缩写
b -- 蓝色
g -- 绿色
r -- 红色
c -- 青色
m -- 品红
y -- 黄色
k -- 黑色
w -- 白色
- 示例
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(9)
y = np.sin(x)
z = np.cos(x)
plt.plot(x,y,marker = '*',linewidth = 1,linestyle = '--',color = 'orange')
plt.plot(x,z)
plt.title('matplotlib')
plt.xlabel('height',fontsize = 15)
plt.ylabel('width',fontsize = 15)
plt.legend(['Y','Z'],loc = 'upper right')
plt.grid(True)
2. 散点图
matplpotlib.pyplot.scatter(x,y,s = None,c = None,marker = None,alpha = None)
-- s参数接收数值或者一维的array,指定点的大小,若传入一维array则表示每个点的大小,默认为None
- 示例1
fig,ax = plt.subplots()
plt.rcParams['font.family'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
x1 = np.arange(1,30)
y1 = np.sin(x1)
ax1 = plt.subplot(1,1,1)
plt.title('散点图')
plt.xlabel('X')
plt.ylabel('Y')
lvalue = x1
ax1.scatter(x1,y1,c = 'r',s = 100,linewidths = lvalue,marker = 'o')
plt.legend('x1')
- 示例2
fig,ax = plt.subplots()
plt.rcParams['font.family'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
for color in ['red','green','blue']:n = 500x,y = np.random.randn(2,n)ax.scatter(x,y,c = color,label = color,alpha = 0.3,edgecolors = 'none')
ax.legend()
ax.grid(True)