着色3D散点图

发布于 2025-02-13 18:48:58 字数 819 浏览 3 评论 0原文

我有一个绘制3D散点图的功能,它可以正常工作,但是我看不出如何根据条件为特定数据点给出颜色:

在以下代码中,我绘制了3个功能; NbactionsD30,AvgactionsMonth和Actionhr。

数据点给出特定的颜色

我想为actionshr值> = 50函数的参数为​​f1,f2,f3的 。数据是数据框 其中包含功能。

这是我函数的代码:

def plot3D(f1, f2, f3, data):

%matplotlib widget
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

xs = data[f1]
ys = data[f2]
zs = data[f3]

fig = plt.figure()
ax = Axes3D(fig)

plot = ax.scatter(xs, ys, zs, s=50, color = 'blue', edgecolors = "white")
ax.set_xlabel(f1)
ax.set_ylabel(f2)
ax.set_zlabel(f3)
plt.show()

plot3D("avgActionsMonth", "nbActionsD30", "actionSHR", data)

”屏幕快照链接“

I have a function to plot 3D scatter plots, it works fine but I don't see how I can give a color to specific data points based on a condition for example:

in The following code I am plotting 3 features; nbActionsD30, avgActionsMonth and actionSHR.

I want to give a specific color to the data points where actionsSHR value >= 50

the parameters of the function are f1, f2, f3 the feature names. data is the dataframe
that contains the features.

here is my function's code :

def plot3D(f1, f2, f3, data):

%matplotlib widget
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

xs = data[f1]
ys = data[f2]
zs = data[f3]

fig = plt.figure()
ax = Axes3D(fig)

plot = ax.scatter(xs, ys, zs, s=50, color = 'blue', edgecolors = "white")
ax.set_xlabel(f1)
ax.set_ylabel(f2)
ax.set_zlabel(f3)
plt.show()

plot3D("avgActionsMonth", "nbActionsD30", "actionSHR", data)

screenshot link

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

第七度阳光i 2025-02-20 18:48:58
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(subplot_kw=dict(projection="3d"))
x, y, z = np.random.normal(size=(3, 1000))
ax.scatter(x, y, z, c=z>1)
plt.show()

给出

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(subplot_kw=dict(projection="3d"))
x, y, z = np.random.normal(size=(3, 1000))
ax.scatter(x, y, z, c=z>1)
plt.show()

gives

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文