import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10, 100) y = np.sin(x) plt.plot(x, y, color=(1, 0, 0)) # 使用RGB元组红色画线 plt.show() 4. 使用颜色映射(Colormap) 如果想要根据数值来设置颜色,可以使用颜色映射(Colormap)。Matplotlib提供了多种预定义的颜色...
1.1 plot方法的具体参数 plt.plot(x,y,color,linestyle,linewidth,marker,markeredgecolor, markeredgwidth,markerfacecolor,markersize,label) 其中,参数x,y分别表示x轴和y轴的数据;color表示折线图的颜色 上面的颜色参数值是颜色缩写代码,color参数值除了用颜色缩写代码表示,还可以用标准颜色名称、十六进制颜色值、RGB元...
plt.plot(x, y2, color='green', label='y2') plt.legend() plt.show() 在这个例子中,我们使用了两次plt.plot()函数,分别为每条线设置不同的颜色,并使用plt.legend()函数添加图例。 三、使用颜色映射 对于更复杂的绘图需求,特别是需要根据数据值动态改变颜色时,可以使用颜色映射(colormap)。Matplotlib提供...
import matplotlib.pyplot as plt import matplotlib as mpl from matplotlib.colors import ListedColormap cmap=mpl.cm.jet_r #获取色条 front_time_list=[0,0,0,0,0,0,0,0,0,0] #保存前向处理时间hist back_tim…
# Dataframe直接生成图表df=pd.DataFrame(np.random.randn(1000,4),index=ts.index,columns=list('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 → 是否...
df2.plot.barh(stacked=True); 1. Histograms AI检测代码解析 df2.plot.hist(alpha=0.5); 1. box AI检测代码解析 df.plot.box(); 1. box可以自定义颜色: AI检测代码解析 color = { ...: "boxes": "DarkGreen", ...: "whiskers": "DarkOrange", .....
(100)colors=np.random.rand(100)# 随机生成颜色值# 创建散点图plt.figure(figsize=(8,6))scatter=plt.scatter(x,y,c=colors,cmap='viridis')plt.colorbar(scatter)# 添加颜色条plt.title('Scatter Plot with Viridis Color Map')plt.xlabel('X Axis Label')plt.ylabel('Y Axis Label')plt.grid(True...
plt.plot([threshold[node],threshold[node]], [x2_min,x2_max],color="black") iffeature[node]==1: plt.plot([x1_min,x1_max],[threshold[node], threshold[node]],color="black") ifchildren_left[node]!=children_right[node]: iffeature[node]==0: ...
: 控制颜⾊, color=‘green’linestyle : 线条风格, linestyle=‘dashed’marker : 标记风格, marker=‘o’markerfacecolor: 标记颜⾊, markerfacecolor=‘blue’markersize: 标记尺⼨, markersize=20 b = np.arange(5)plt.plot(b,b*1.0,'g.-',b,b*1.5,'rx',b,b*2.0, 'b')plt.show()
![custom_color_plot.png]( 三、使用colormap colormap是一种能够根据数据值自动调整颜色的方法。在matplotlib中,可以使用一系列预定义的colormap,也可以自定义colormap。 3.1 预定义colormap matplotlib中有许多预定义的colormap供我们使用,比如’viridis’、‘plasma’、'inferno’等。下面是一些常用的预定义colormap...