0
我正在嘗試使用matplotlib和python來構建3d散點圖。 這個問題看起來像下面這樣:3D圖上的點的偏移使得無法理解它們究竟屬於哪裏。使用matplotlib無偏移的3d散點圖
在該圖中,觀察到這些點並不完全與頂點一致。也就是說,根據圖表顯示,在0B和1B和4S之間存在一個點,它不包含在數據集中(見下面的代碼MWE)。有什麼需要做的設置偏移?
#!/usr/bin/env python
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
from mpl_toolkits.mplot3d import Axes3D
import string
from matplotlib import cm
import matplotlib
def plot_state_transition():
xTickMarks = ["-1B","0B", "1B", "2B", "3B"]#, "4B"]#, "1B3S", "2B2S"]
yTickMarks = ["-1S","0S", "1S", "2S", "3S", "4S"]
zTickMarks = ["0", "0.6", "0.65", "0.9", "1.15"]
matplotlib.rc('font', serif='Helvetica Neue')
matplotlib.rc('text', usetex='false')
matplotlib.rcParams.update({'font.size': 10})
fig = plt.figure(figsize=(11.69,4.88)) # for landscape
axes1 = fig.add_subplot(111, projection='3d')
savename = "state-transition.png"
tup = []
plt.grid(True,linestyle='-',color='0.75')
X_AXIS = ['2B', '2B', '1B', '2B', '2B', '2B', '1B', '2B']
Y_AXIS = ['0S', '2S', '3S', '2S', '2S', '2S', '3S', '2S']
Z_AXIS = ['0.6', '0.6', '0.6', '0.6', '0.6', '0.9', '0.9', '0.9']
s = [12.900648500000001, 12.705360163934426, 13.021028032786887, 13.258014354838707, 14.418979838709676, 17.092295806451613, 15.625246451612906, 17.484319354838711]
x = [xTickMarks.index(i) for i in X_AXIS]
y = [yTickMarks.index(i) for i in Y_AXIS]
z = [zTickMarks.index(i) for i in Z_AXIS]
s = s
axes1.scatter(x, y, z, c='r', marker='o')
axes1.set_xlim((0, len(xTickMarks)-1))
axes1.set_ylim((0, len(yTickMarks)-1))
axes1.set_zlim((0, len(zTickMarks)-1))
axes1.set_xticks(xrange(len(xTickMarks)))
axes1.set_yticks(xrange(len(yTickMarks)))
axes1.set_zticks(xrange(len(zTickMarks)))
axes1.set_xticklabels(xTickMarks)
axes1.set_yticklabels(yTickMarks)
axes1.set_zticklabels(zTickMarks)
axes1.set_ylabel('Small cores')
axes1.set_zlabel('Frequency')
axes1.set_xlabel('Big cores')
axes1.xaxis.grid(True)
figsize=(11.69,8.27) # for landscape
fig.savefig(savepath + savename, bbox_inches='tight', dpi=300, pad_inches=0.1)
plt.clf()
def main():
plot_state_transition()
if __name__ == "__main__":
main()
這很有道理。我會嘗試穿過不同的視角,然後看看。謝謝。 – tandem
當我在做3D圖時,我經常通過大範圍的視圖(例如,從-90到90移動2 o步。這真的會帶來「3D性」,並大大減少了與視角有關的偏移問題。顯然,如果您在紙上發佈,但是網絡發佈等可以很好地處理它,那麼這是不好的。把它變成gif – iayork
但是,你怎麼把它變成gif?你能給個例子嗎 ? – tandem