简体   繁体   English

Axes3D.text()注释3D散点图

[英]Axes3D.text() Annotate 3D Scatter Plot

Can't get the 3D text working to annotate the scatter plot points. 无法使3D文本工作以注释散点图点。

Tried Axes3D.text, plt.text but keep getting 'missing required positional argument 's'. 尝试过Axes3D.text,plt.text,但仍然得到'缺少必需的位置参数'。 How do you annotate in 3D in a loop? 你如何在循环中注释3D?

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
import pandas as pd
import numpy as np

df = pd.read_csv (r'J:\Temp\Michael\Python\9785.csv')

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

#Scatter plot
for i in df.index:
    x = df.at[i,'x']
    y = df.at[i,'y']
    z = df.at[i,'h']
    ax.scatter(xs=x, ys=y, zs=z, s=20,color='red',marker='^')
    label = df.at[i,'to']
    Axes3D.text(x+0.8,y+0.8,z+0.8, label, zdir=x)

TypeError: text() missing 1 required positional argument: 's' TypeError:text()缺少1个必需的位置参数:'s'

Changing: ax = fig.add_subplot(111, projection='3d') 更改:ax = fig.add_subplot(111,projection ='3d')

to: ax = fig.gca(projection='3d') to:ax = fig.gca(projection ='3d')

solved the problem. 解决了这个问题。 Used ax.text. 使用了ax.text。

from mpl_toolkits.mplot3d import Axes3D 
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
import pandas as pd
import numpy as np

df = pd.read_csv (r'J:\Temp\Michael\Python\9785.csv')

fig = plt.figure()
ax = fig.gca(projection='3d')

#Scatter plot
for i in df.index:
    df.set_index('to')
    x = df.at[i,'x']
    y = df.at[i,'y']
    z = df.at[i,'h']
    ax.scatter(xs=x, ys=y, zs=z, s=20,color='red',marker='^')
    ax.text(x+0.8,y+0.8,z+0.8, df.at[i,'to'], size=10, zorder=1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM