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()...
1importmatplotlib.pyplot as plt2importnumpy as np34#Generate some data...5data = np.random.random((100, 1))6#y = data.mean(axis=0)7#x = np.random.random(y.size) * 108#x -= x.min()9#x.sort()1011#Plot a line between the means of each dataset12#plt.plot(x, y, 'b-')1...
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指定。
这个例子将文本旋转了45度。rotation参数可以接受度数值或’vertical’、’horizontal’等预设值。 3. 结合axhline和text 现在我们已经了解了axhline和text的基本用法,让我们看看如何结合这两个函数来创建更有信息量的图表。 3.1 标记平均值 一个常见的用例是使用水平线标记数据的平均值,并添加文本说明: ...
_ 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-.'); ...
d Thin diamond marker|Vertical line (vlinesymbol) marker _ Horizontal line (hline symbol) marker+Plus marker xCross(x) marker B.函数图(折线图) 数据还是上面的。 fig = plt.figure(figsize=(12,6)) plt.subplot(121) plt.plot(x, y, color='r', linestyle='-') ...
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...
linefmt,线条的线型和颜色,'[line][color]',类似于 plot 的 fmt 参数。 markerfmt,标记点的形状,类似于 plot 的 fmt 参数 basefmt,定义基线属性的格式字符串。 orientation,方向,{'vertical','horizontal'},默认'vertical' bottom,条形基底部的 y 坐标,float, default: 0 ...
>>> plot(x, y) # plot x and y using default line style and color >>> plot(x, y, 'bo') # plot x and y using blue circle markers >>> plot(y) # plot y using x as index array 0..N-1 >>> plot(y, 'r+') # ditto, but with red plusses ...