Matplotlib重叠颜色和标记

时间:2016-10-26 23:44:45

标签: python matplotlib

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

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

for color, marker in [('g', 'x'), ('r', 'o'), ('b', '^')]:
    ax.scatter(x[:100],y[:100],z[:100], marker=marker, color=color, s=50, alpha=.3)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()

让我这个

enter image description here

但我想要这个

enter image description here

我尝试过改变facecolor和edgecolor但没有帮助。

教程代码似乎按照我想要的方式工作,并且不会重叠标记并获得正确的颜色。没有循环,有更简单的方法吗?

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


def randrange(n, vmin, vmax):
    return (vmax - vmin)*np.random.rand(n) + vmin

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
n = 100
for c, m, zl, zh in [('g', 'o', -50, -25), ('b', '^', -30, -5), ('r', 'x', -30, -5)]:
    xs = randrange(n, 23, 32)
    ys = randrange(n, 0, 100)
    zs = randrange(n, zl, zh)
    ax.scatter(xs, ys, zs, edgecolor=(0,0,0,0), c=c, marker=m)

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()

0 个答案:

没有答案