简体   繁体   English

Python-如何在散点图上显示单个数据点?

[英]Python - How to display a single data point on a scatter plot?

I'm trying to display a 3D scatter plots. 我正在尝试显示3D散点图。 The code below works but it displays the current and old data points. 下面的代码可以工作,但是它显示当前和旧数据点。 I would like to display only one at a time. 我想一次只显示一个。 I've tried different options but I can't get it to work properly. 我尝试了其他选项,但无法正常工作。 Any suggestions? 有什么建议么?

Thanks! 谢谢!

import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D

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

ax.set_xlim([-1.5, 1.5])
ax.set_ylim([-1.5, 1.5])
ax.set_zlim(0, 1.5)

ax.set_xlabel('x axis')
ax.set_ylabel('y axis')
ax.set_zlabel('z axis')

data = [[-1.0, -1.0, 0.0], [1.0, -1.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 0.0, 1.0]]

def animate(data):

    x = data[0]
    y = data[1]
    z = data[2]

    scat = ax.scatter3D(x, y, z, c='r', marker='o')

    return

ani = animation.FuncAnimation(fig, animate, data, interval=1000, blit=False, repeat=False)

plt.show()

You can clear the axes in each iteration in the for loop. 您可以在for循环中的每次迭代中清除轴。 Note that you need to take care of the axes limits as well. 请注意,您还需要注意轴的限制。

import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D

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

ax.set_xlim([-1.5, 1.5])
ax.set_ylim([-1.5, 1.5])
ax.set_zlim(0, 1.5)

ax.set_xlabel('x axis')
ax.set_ylabel('y axis')
ax.set_zlabel('z axis')

data = [[-1.0, -1.0, 0.0], [1.0, -1.0, 0.0], [0.0, -1.0, 1.0], [-1.0, 0.0, 1.0]]

def animate(data):

    x = data[0]
    y = data[1]
    z = data[2]

    plt.cla()
    ax.set_xlim([-1.5,1.5])
    ax.set_ylim([-1.5,1.5])
    ax.set_zlim([-1.5,1.5])
    scat = ax.scatter3D(x, y, z, c='r', marker='o')

    return

ani = animation.FuncAnimation(fig, animate, data, interval=1000, blit=False, repeat=False)

plt.show()

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

相关问题 如何将数据(或单点)添加到现有的3d scatter plotly exprees plot in python - How to add data (or single point) to an existing 3d scatter plotly exprees plot in python 如何使用 plotly express 突出显示散点图 plot 上的单个数据点 - How to highlight a single data point on a scatter plot using plotly express 突出显示散点图上的单个点 - Highlight a single point on a scatter plot Python:如何在cartopy地图上的特定点绘制散点图? - Python: How to plot scatter plot at specific point on map in cartopy? 在Matplotlib Python中注释散点图中的每个数据点 - Annotating every data point in scatter plot in matplotlib python Python/Plotly:如何使 Scatter plot 上的每个数据点代表中值? - Python/Plotly: How to make each data point on Scatter plot represent median value? Python散点图-如何查看每点的条目数 - Python scatter plot - how to see number of entries per point Python matplotlib:如何为散点图中的每个点分配不同的不透明度? - Python matplotlib: How to assign a different opacity to each point in a scatter plot? 如何将多条曲线拟合到单个数据散点图? - How to fit multiple curves to a single scatter plot of data? Python中具有无穷小点大小的散点图 - Scatter plot with infinitesimal point size in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM