简体   繁体   English

在python中将2D图形转换为3D

[英]Turning 2D graphics into 3D in python

In 2D I have my x that gets the value of the x and y coordinates: 在2D中我有我的x,它获取x和y坐标的值:

x = [[0.72,0.82]]

And at some point in the code I use this: 在代码中的某些时候我使用这个:

plt.plot(x[i][0], x[i][1], 'go', markersize=15, alpha=.5)

Now I have an x that gets the value of the x, y, and z coordinates: 现在我有一个x,它获取x,y和z坐标的值:

x = [[0.72,0.82,-0.77]]

And I want to reproduce the same effect of 2D only now in 3D, I tried to do something like: 我想现在只在3D中重现2D的相同效果,我尝试做类似的事情:

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_zlim(-1, 1)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

ax.scatter(x[i][0], x[i][1], x[i][2], 'go', markersize=15, alpha=.5)

But I get the following error: 但是我收到以下错误:

AttributeError: Unknown property markersize

PS: I'm using: PS:我正在使用:

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

I'd like to know how can I plot them correctly. 我想知道如何正确绘制它们。

Check matplotlib reference for ax.scatter arguments, markerzise and alpha are not there, to change points' size you should use s argument, something like: 检查matplotlib参考ax.scatter参数, markerzisealpha不存在,改变点的大小你应该使用s参数,如:

ax.scatter(xs, ys, zs, s=10, c=c, marker=m)

Notice s can also be an array of the same length as xs if you want points' size to be proportional to it's xs value. 注意s也可以是与xs长度相同的数组,如果您希望点的大小与其xs值成比例。

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

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