y,label='Data Points')ax.axhline(y=np.mean(y),color='r',linestyle='--',label='Mean')ax.legend()ax.set_title('Scatter Plot with Horizontal Mean Line - how2matplotlib.com')plt.show()
6))plt.scatter(x,y,alpha=0.5)plt.axhline(y=0.5,color='r',linestyle='--',label='Threshold')plt.title('Scatter Plot with Horizontal Reference Line - how2matplotlib.com')plt.xlabel('X-axis')plt.ylabel('Y-axis')plt.legend()plt.show()...
np.random.seed(42)data=np.random.randn(100)mean=np.mean(data)fig,ax=plt.subplots()ax.plot(data)ax.axhline(y=mean,color='r',linestyle='--')ax.text(len(data)/2,mean,f'Mean:{mean:.2f}',fontsize=10,va='bottom',ha='center')ax.set_title('How2matplotlib.com - Mean Value Marker...
fig, ax = plt.subplots() ax.plot(x, y) # 绘制垂直线 ax.axvline(x=5, color='r', linestyle='--', label='vertical line') # 绘制水平线 ax.axhline(y=0, color='b', linestyle='-', label='horizontal line') 在上面的代码中,我们使用axvline函数绘制了一条垂直线,其位置由x=5指定。
(x)+np.random.normal(0,0.1,100)fig,ax=plt.subplots()ax.plot(x,y)ax.axhline(y=0.5,color='r',linestyle='--',label='Upper Threshold')ax.axhline(y=-0.5,color='g',linestyle='--',label='Lower Threshold')ax.legend()ax.set_title('Marking thresholds with axhline - how2matplotlib....
_ Horizontal line (hline symbol) marker + Plus marker x Cross (x) marker 下面的实例集合以上三种:具体代码和效果如下所示: import matplotlib.pyplot as plt import numpy as np y = np.arange(1,3,0.3) plt.plot(y,'cx--', y+1,'mo:', y+2,'kp-.'); ...
importmatplotlib.pyplotaspltimportnumpyasnp# 生成数据x=np.linspace(0,10,100)y=np.sin(x)# 绘制图形plt.plot(x,y,label='Sine Wave')plt.axhline(y=0,color='r',linestyle='--',label='y=0 line')plt.title('Sine Wave with Horizontal Line')plt.xlabel('X-axis')plt.ylabel('Y-axis')plt...
(x, y, 'b-')1314#Save the default tick positions, so we can reset them...15#locs, labels = plt.xticks()1617#boxplot18plt.boxplot(data)#, positions=x, notch=True)1920#horizontal line plot21axes =plt.gca()22left, right =axes.get_xlim()23axes.hlines(y=0.5, xmin=left, xmax=...
(x, y, 'b-')1314#Save the default tick positions, so we can reset them...15#locs, labels = plt.xticks()1617#boxplot18plt.boxplot(data)#, positions=x, notch=True)1920#horizontal line plot21axes =plt.gca()22left, right =axes.get_xlim()23axes.hlines(y=0.5, xmin=left, xmax=...
The simplest way to create a line plot in Matplotlib is by using theplot()function. Here’s how you can do it: import matplotlib.pyplot as plt import numpy as np # Create some sample data x = np.arange(0, 10, 0.1) y = np.sin(x) ...