我有一个用于子图的脚本,我在子图的文本和箭头(脚本的结尾)上添加了脚本。如何添加散点图?我尝试过:
scatter = fig.add_scatter(0.5, 0.5, marker = '_', s=300)
fig.add_scatter(0.5, 0.5, marker = '_', s=300)
错误是:'Figure'对象没有属性'add_scatter'
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D # 3d graph
from mpl_toolkits.mplot3d import proj3d # 3d graph
from matplotlib.text import Text
from matplotlib.patches import Arrow
# Plot subplot
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 2, figsize=(10,13))
x = [0, 1]
y = [0, 5]
fig1 = plt.subplot(421)
plt.plot(x,y)
fig2 = plt.subplot(422)
plt.plot(x,y)
fig3 = plt.subplot(423, projection = '3d') # number of vertical figures, number of horizontal figures, order
# Plot figure with size
fig4=plt.subplot(424, projection = '3d')
fig5=plt.subplot(425, projection = '3d')
fig6=plt.subplot(426, projection = '3d')
fig7=plt.subplot(427, projection = '3d')
fig8=plt.subplot(428, projection = '3d')
text = fig.add_artist(Text(0.56,0.198, text='Hello'))
arrow = fig.add_artist(Arrow(0.52, 0.6, 0, -0.08, width=.02))
plt.show()
期望的结果是在第3个和第4个子图之间添加散点。
您可能不理解问题的全部含义,但是可以使用以下代码绘制散点图。
N=100
X = np.random.rand(N, 3)
y = np.random.rand(N) * 2 - 1
fig3.scatter(X[:, 0], X[:, 1],zs=X[:, 2],zdir='z', s=50, c=y, cmap=plt.cm.jet)