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()
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...
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...
importmatplotlib.pyplotasplt categories=['Category A','Category B','Category C','Category D']values=[4,7,2,5]plt.figure(figsize=(10,6))plt.barh(categories,values)plt.title('Basic Horizontal Bar Chart - how2matplotlib.com')plt.xlabel('Values')plt.ylabel('Categories')plt.show() Python ...
‘line’ : line plot (default)#折线图 ‘bar’ : vertical bar plot#条形图 ‘barh’ : horizontal bar plot#横向条形图 ‘hist’ : histogram#柱状图 ‘box’ : boxplot#箱线图 ‘kde’ : Kernel Density Estimation plot#Kernel 的密度估计图,主要对柱状图添加Kernel 概率密度线 ...
('ABCD')) df=df.cumsum() df.plot(kind='line', style='--.', alpha=0.4, use_index=True, rot=45, grid=True, figsize=(8,4), title='test', legend=True, subplots=False, colormap='Greens') # 选择色系 # subplots → 是否将各个列绘制到不同图表,默认为False # 也可以用 plt.plot(df...
line, = ax.plot(x,np.sin(x)) def animate(i): line.set_ydata(np.sin(x + i/10.0))#updata the data return line, def init(): line.set_ydata(np.sin(x)) return line, # call the animator. blit=True means only re-draw the parts that have changed. ...
_ Horizontal line (hline symbol) marker Plus marker x Cross (x) marker 下面的实例集合以上三种:具体代码和效果如下所示: importmatplotlib.pyplotaspltimportnumpyasnp y = np.arange(1,3,0.3) plt.plot(y,'cx--', y+1,'mo:', y+2,'kp-.'); ...
_ 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-.'); ...
formatting like color, markerandlinestyle. It's a shortcut string notation described in the *Notes* section below. >>> 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 ...