from matplotlib.patches import Rectangle
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(10, 5))
# matplotlib.rcParams['font.family'] = 'SimHei' # 设置字体为中文宋体
ax.set_ylim(0, 5)
ax.set_xlim(0, 10)
ax.grid()
ax.scatter(6, 3, color='red', marker="*")
ax.tick_params(size=12)
patch = mpatches.Patch(color='blue', label='legend')
ax.legend(handles=[patch], loc='upper left',
bbox_to_anchor=(6/10, 3/5),
borderaxespad=0,
fontsize=18, edgecolor='yellow')
# ax.annotate('(14, 6)', xy=(14, 6), xytext=(15, 6.5),arrowprops={'arrowstyle':'->'}, fontsize=18)
ax.text(5.5, 3.3,
'The point at upper left of legend matches (x, y)',
fontsize=18)
推薦hahow線上學習python: https://igrape.net/30afN