我想1x1使用meshgrid. 介紹了當前和預期的產出。
import numpy as np
import matplotlib.pyplot as plt
X = np.array([0,1,2])
Y = np.array([0, -1, -2])
xx, yy = np.meshgrid(X,Y)
plt.plot(xx, yy,"s")
plt.show()
當前輸出為

預期的輸出是

uj5u.com熱心網友回復:
我嘗試建議以下解決方案。假設我們有 1x1 正方形,meshgrid則不需要:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
X = np.array([0, 1, 2])
Y = np.array([0, -1, -2])
x_sorted = np.sort(X)
y_sorted = np.sort(Y)
ax.set_xticks(x_sorted)
ax.set_yticks(y_sorted)
ax.set_xlim(x_sorted[0], x_sorted[-1])
ax.set_ylim(y_sorted[0], y_sorted[-1])
ax.grid()
ax.set_aspect('equal', 'box')
plt.show()

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/497784.html
標籤:Python 麻木的 matplotlib
下一篇:將索引陣列與值陣列組合
