import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
x = np.linspace(0,60,300)
y = np.sin(x)
z = np.cos(x)
fig = plt.figure(figsize=(9,6))
a3 = Axes3D(fig)# 二维变成3D
a3.plot(x,y,z)
plt.figure(figsize=(9,6))# projection='3d' 指定了这个子图的投影类型为3D
a3 = plt.subplot(111, projection ='3d')
a3.plot(x,y,z)# 普通线形图
a3.set_xlabel('X')
a3.set_ylabel('Y')
a3.set_zlabel('Z')# 散点图
x = np.random.randint(0,60,size =20)
y = np.random.randn(20)
z = np.random.randn(20)
a3.scatter(x,y,z,color='red')# 调整视图的角度# elev=20示观察者向上仰角 20 度看图# azim=-30 观察者沿着 z 轴逆时针旋转 30 度来观察图形
a3.view_init(elev =20,azim=-30)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')# 创建一个网格,其中 x 方向和 y 方向都是 [0, 1, 2, 3, 4]
x, y = np.meshgrid(np.arange(5), np.arange(5))
x = x.flatten()
y = y.flatten()
z = np.zeros_like(x)
dx = dy =0.3
dz = np.random.randint(1,10,len(z))# 绘制3D条形图
ax.bar3d(x, y, z, dx, dy, dz, shade=True)# 设置坐标轴标签
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
seaborn 快速入门
import seaborn as sns
# style='ticks' 坐标轴显示刻度线# context='paper': 指定绘图的上下文环境, 从而调整图形的大小和比例
sns.set(style ='ticks',context ='paper',font ='STKaiti')# 设置样式
plt.figure(figsize=(9,6))
x = np.linspace(0,2*np.pi,20)
y = np.sin(x)# lineplot方法,画一条线
sns.lineplot(x = x, y = y, color ='green', ls ='--')
sns.lineplot(x = x, y = np.cos(x), color ='red', ls ='-.')
线形图
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
sns.set(style ='dark',context ='notebook',font ='SimHei')# 设置样式
plt.figure(figsize=(9,6))# 加载数据
fmri = pd.read_csv('./fmri.csv')# fmri这一核磁共振数据
fmri['event'].unique()# array(['stim', 'cue'], dtype=object)
fmri.head()