【发布时间】:2021-11-11 12:53:24
【问题描述】:
我正在尝试在我拥有的 3D 散点图上获取误差线。我在这里看到过这个主题'在 python 中使用 scatter3D 绘制列表或数组的列'但是我的是一个 z 值数组和相应的错误值数组。
这里是代码
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits import mplot3d
df = pd. read_csv(r'C:\Users\brown\Dropbox\Thesis\8. Pharm Method development 5 - IDR zone\Excel docs\test.csv')
print (df)
#data
fx = (0.5,1.5,2,6)
fy = (25,20.5,16)
z = [37.8 38.61 42.29 43.8
32.47 33.34 38.39 39.19
24.68 26.32 28.49 30.58]
x, y = np.meshgrid(fx, fy)
#error data
zerror = [3.1 3.7 3.7 4.36
1.44 1.47 2.85 2.2
0.7 0.49 2.03 1.47]
#plot points
fig = plt.figure(figsize = (10,10))
ax = fig.gca(projection='3d')
surf=ax.scatter3D(x, y, z, c=z, cmap="jet", s=200, edgecolors="black", linewidth=1, marker= "^", antialiased=False)
fig.colorbar(surf, shrink=0.5, aspect=10)
ax.set_xlabel('Measurement zone area (mm²)')
ax.set_ylabel('Distance from compact (mm)')
ax.set_zlabel('IDR (µg/min/cm²)')
ax.set_title('Ibuprofen non-plate')
ax.view_init(30, 300)
plt.rcParams["axes.edgecolor"] = "yellow"
plt.rcParams["axes.linewidth"] = 2
#plot errorbars
for i in np.arange(0, len(fx)):
ax.plot([x[i], x[i]], [y[i], y[i]], [z[i]+zerror[i], z[i]-zerror[i]], marker="_")
**Data frame values**
a a sd b b sd c c sd d d sd
0 37.80 3.10 38.61 3.70 42.29 3.70 43.80 4.36
1 32.47 1.44 33.34 1.47 38.39 2.85 39.19 2.20
2 24.68 0.70 26.32 0.49 28.49 2.03 30.58 1.47
我得到一个 3D 散点图,所有点都打开,但没有误差线。
我收到错误消息“输入操作数的维度超过轴重新映射允许的维度”
非常感谢任何帮助,
非常感谢
【问题讨论】:
-
按原样,如果不访问您的 csv 文件,我们将无法测试您的代码。您可以编辑您的问题并将从数据框中获得的值替换为重现您的问题的值(在代码中声明)吗?
-
嗨,当然,我已经将它们作为数据框粘贴在底部,并将它们放在代码主体中。
标签: python arrays matplotlib errorbar scatter3d