1、需要注意的問題
- 解決 MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented warnings.warn(str, mplDeprecation 問題
import warnings
warnings.filterwarnings("ignore",".*GUI is implemented.*")
plt.pause(0)
2、具體代碼test.py:
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
import numpy as np
import math
import warnings
# 解決(MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented warnings.warn(str, mplDeprecation)
warnings.filterwarnings("ignore",".*GUI is implemented.*")
fig = plt.figure()
# 連續性的畫圖
ax = fig.add_subplot(1, 1, 1)
# 設置圖像顯示的時候XY軸比例
ax.axis("equal")
# 開啟一個畫圖的窗口
plt.ion()
print('開始仿真')
try:
for i in range(20):
x = np.random.randn()
y = np.random.randn()
if x < 0.5:
ax.scatter(x, y, c='r', marker='v') # 散點圖
else:
ax.scatter(x, y, c='b', marker='.') # 散點圖
plt.axvline(0.5) # 畫出豎線 (y=0.5)
plt.axvline(-0.5) # 畫出豎線 (y=-.5)
# 停頓時間
plt.pause(0.1)
except Exception as err:
print(err)
# 防止運行結束時閃退
plt.pause(0)