1.数据类型部分如下:
group A B CA-1 0 0 0.1273 A-1 20 12 0.1087 A-1 40 36 0.1313 A-1 60 24 0.0865 A-1 80 12 0.0980 A-1 100 0 0.0860 A-1 120 12 0.0520 A-1 140 36 0.0475 B-1 0 0 0.1293 B-1 20 12 0.1097 B-1 40 36 0.1223 B-1 60 24 0.0765 B-1 80 12 0.0190 B-1 100 0 0.0890 B-1 120 12 0.0510 B-1 140 36 0.0575 C-1 0 0 0.1293 C-1 20 12 0.1067 C-1 40 36 0.1223 C-1 60 24 0.0865 C-1 80 12 0.0970 C-1 100 0 0.0760 C-1 120 12 0.0510 C-1 140 36 0.0575 D-1 0 0 0.1283 D-1 20 12 0.1197 D-1 40 36 0.1313 D-1 60 24 0.0765 D-1 80 12 0.0880 D-1 100 0 0.0860 D-1 120 12 0.0520 D-1 140 36 0.0465
三维图像之散点图代码如下:
from mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as pltimport pandas as pd file = 'C:\\Users\Desktop\huatu.txt'data = pd.read_csv(file, sep="\t")#print(data)def sample_x(): #取出x轴数据 df = [] sample_type1 = data.group.unique() for i in sample_type1: a=data.concentration[data.group == i] df.append(a) return dfx1,x2,x3,x4 = sample_x()[0],sample_x()[1],sample_x()[2],sample_x()[3] def sample_y(): #取出y轴数据 df1 = [] sample_type1 = data.group.unique() for i in sample_type1: b=data.time[data.group == i] df1.append(b) return df1y1,y2,y3,y4 = sample_y()[0],sample_y()[1],sample_y()[2],sample_y()[3] def sample_z(): #取出z轴数据 df2 = [] sample_type1 = data.group.unique() for i in sample_type1: c=data.OD600[data.group == i] df2.append(c) return df2z1,z2,z3,z4 = sample_z()[0],sample_z()[1],sample_z()[2],sample_z()[3] # 绘制散点图fig = plt.figure()ax = Axes3D(fig) ax.scatter(x1, y1, z1, c='r', label='A')ax.scatter(x2, y2, z2, c='g', label='B')ax.scatter(x3, y3, z3, c='y', label='C')ax.scatter(x4, y4, z4, c='b', label='D') # 绘制图例ax.legend(loc='best') # 添加坐标轴(顺序是Z, Y, X)ax.set_zlabel('Z', fontdict={'size': 15, 'color': 'red'})ax.set_ylabel('Y', fontdict={'size': 15, 'color': 'red'})ax.set_xlabel('X', fontdict={'size': 15, 'color': 'red'}) plt.show()
三维图像之曲线图代码如下:
from mpl_toolkits.mplot3d import axes3dimport matplotlib.pyplot as pltimport pandas as pd file = 'C:\\Users\Desktop\huatu.txt'data = pd.read_csv(file, sep="\t")#print(data)def sample_x(): #取出x轴数据 df = [] sample_type1 = data.group.unique() for i in sample_type1: a=data.concentration[data.group == i] df.append(a) return dfx1,x2,x3,x4 = sample_x()[0],sample_x()[1],sample_x()[2],sample_x()[3] def sample_y(): #取出y轴数据 df1 = [] sample_type1 = data.group.unique() for i in sample_type1: b=data.time[data.group == i] df1.append(b) return df1y1,y2,y3,y4 = sample_y()[0],sample_y()[1],sample_y()[2],sample_y()[3] def sample_z(): #取出z轴数据 df2 = [] sample_type1 = data.group.unique() for i in sample_type1: c=data.OD600[data.group == i] df2.append(c) return df2z1,z2,z3,z4 = sample_z()[0],sample_z()[1],sample_z()[2],sample_z()[3] # new a figure and set it into 3dfig = plt.figure()ax = fig.gca(projection='3d') # set figure informationax.set_title("3D")ax.set_xlabel("X")ax.set_ylabel("Y")ax.set_zlabel("Z") # draw the figure, the color is r = readfigure1 = ax.plot(x1, y1, z1, c='r')figure2 = ax.plot(x2, y2, z2, c='b')figure3 = ax.plot(x3, x3, z3, c='g')figure4 = ax.plot(x4, x4, z4, c='y') plt.show()
如果觉得《matplotlib 散点图_Python学习 —— matplotlib绘制三维曲线图和三维散点图》对你有帮助,请点赞、收藏,并留下你的观点哦!