這個問題在這里已經有了答案: 使用 matplotlib 繪制水平線 7 個回答 2 天前關閉。
我想用matplotlib的plt.axhline()函式畫一條水平線,但我希望水平線停在x軸上的絕對值5處。我如何設定xmax在plt.axhline()5 點停止?
plt.figure()
plt.plot(np.arange(-60, 60, 20), np.arange(0, 1.2, 0.2))
plt.axhline(y = 0.5, xmax = 5, c= 'r')
uj5u.com熱心網友回復:
您需要改為使用plt.hlines,還需要指定 axmin并更改c為color。
import matplotlib.pyplot as plt
import numpy as np
xmin = -65
plt.figure()
plt.plot(np.arange(-60, 60, 20), np.arange(0, 1.2, 0.2))
plt.hlines(y = 0.5, xmin=xmin , xmax = 5, color= 'r')
plt.xlim(left=xmin);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/350091.html
標籤:Python matplotlib 水平线
