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)
![Python: matplotlib如何控制legend的位置? ax.legend(handles=[patch], loc='upper left', bbox_to_anchor=(6/10, 3/5) - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2023/05/20230502163945_79.png)
推薦hahow線上學習python: https://igrape.net/30afN






![Python: 如何使用pandas.to_numeric ( df[‘numbers’], errors=’coerce’) 將非數值型資料轉為NaN? df[‘numbers’].describe() 簡述統計資料 Python: 如何使用pandas.to_numeric ( df[‘numbers’], errors=’coerce’) 將非數值型資料轉為NaN? df[‘numbers’].describe() 簡述統計資料](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2024/05/20240501052102_0.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言