Я собираюсь взять трехмерный график рассеяния, используя matplotlib, но у меня есть некоторые проблемы.
У меня есть 3 переменные, которые (a: 70, b: 144, c: 3) имеют различную форму каждой.
Итак, возникает ошибка значения. Как я могу сделать 3D-график рассеяния?
print(a.shape)
print(b.shape)
print(c.shape)
(70,) (144,) (3,)
# scattering
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(111, projection='3d') # Axe3D object
sample_size = 500
x = np.array(a)
y = np.array(b)
z = np.array(c)
ax.scatter(x, y, z, alpha=0.5, cmap=plt.cm.Greens)
plt.title("ax.scatter")
plt.show()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-58-4590f65025fd> in <module>
11 y = np.array(ex1_non_split_abn['ptp'])
12 z = np.array(initial_non_split_abn['ptp'])
---> 13 ax.scatter(x, y, z, alpha=0.5, cmap=plt.cm.Greens)
14 # plt.savefig('../../assets/images/markdown_img/180612_1225_3dplotting_scattering.svg')
15 plt.title("ax.scatter")
~\Anaconda3\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py in scatter(self, xs, ys, zs, zdir, s, c,
depthshade, *args, **kwargs)
2298
2299 xs, ys, zs = np.broadcast_arrays(
-> 2300 *[np.ravel(np.ma.filled(t, np.nan)) for t in [xs, ys, zs]])
2301 s = np.ma.ravel(s) # This doesn't have to match x, y in size.
2302
~\Anaconda3\lib\site-packages\numpy\lib\stride_tricks.py in broadcast_arrays(*args, **kwargs)
257 args = [np.array(_m, copy=False, subok=subok) for _m in args]
258
--> 259 shape = _broadcast_shape(*args)
260
261 if all(array.shape == shape for array in args):
~\Anaconda3\lib\site-packages\numpy\lib\stride_tricks.py in _broadcast_shape(*args)
191 # use the old-iterator because np.nditer does not handle size 0 arrays
192 # consistently
--> 193 b = np.broadcast(*args[:32])
194 # unfortunately, it cannot handle 32 or more arguments directly
195 for pos in range(32, len(args), 31):
ValueError: shape mismatch: objects cannot be broadcast to a single shape