首页 > 解决方案 > matplotlib 3D:多行

问题描述

使用 matplotlib,是否可以在不使用 for 循环的情况下绘制多条线?因为数据完全不同。

from mpl_toolkits import mplot3d
import pandas as pd
import numpy as np
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

从excel中获取数据

第一行

df1 = pd.read_excel (r'C:/Users/pathar.xlsx', sheet_name= '1')
#print (df1)
zline = df1['Simul_1']

yline = df1['land']
xline = df1['Dis_peak_1']

图尺寸

fig = plt.figure()

fig.set_figwidth(15)
fig.set_figheight(12)

然后绘制第一条带点的线

ax = plt.axes(projection='3d')
ax.plot3D(xline, yline, zline,'red')
ax.view_init(20, -70)
ax.scatter3D(xline, yline, zline,c='k');

第二行

df2 = pd.read_excel (r'C:/Users/pathar.xlsx', sheet_name= '2')
#print (df2)
zline2 = df2['Simul_2']

yline2 = df2['land']
xline2 = df2['Dis_peak_2']


fig = plt.figure()

fig.set_figwidth(15)
fig.set_figheight(12)


ax = plt.axes(projection='3d')
ax.plot3D(xline2, yline2, zline2,'red')
ax.view_init(20, -70)
ax.scatter3D(xline2, yline2, zline2,c='k');

但是当我使用相同的方法绘制第二行时,它不起作用。虽然它适用于 2D 情节

标签: pythonmatplotlibplot

解决方案


推荐阅读