在Matplotlib中,colormap通常用于将标量数据映射到颜色空间。当我们在scatter()函数中使用colormap时,我们实际上是在为每个点分配一个颜色,这个颜色基于点的数值大小。例如,如果我们有一个表示温度的数值列表,并将其映射到颜色空间,那么较低的温度值可能会对应蓝色,而较高的温度值可能会对应红色。 突出数据的规律: co...
importmatplotlib.pyplotaspltimportnumpyasnp# 创建一个包含正负值的数据集x=np.linspace(-5,5,100)y=x**3# 使用 'RdBu' 发散色彩映射表plt.scatter(x,y,c=y,cmap='RdBu')plt.colorbar(label='y = x^3')plt.title('How2matplotlib.com: Diverging Colormap Example (RdBu)')plt.axhline(y=0,col...
Matplotlib 提供了多种 colormap,我们可以使用cm.get_cmap()来获取。 # 选择 colormapcmap=cm.get_cmap('viridis')# 'viridis' 是一种常用的 colormap# 绘制图表plt.scatter(x,y,c=z,cmap=cmap)# 使用 colormap 进行散点图绘制plt.colorbar()# 显示色条 1. 2. 3. 4. 5. 6. cm.get_cmap('viri...
importmatplotlib.pyplotaspltimportnumpyasnp# 创建数据x=np.linspace(-5,5,100)y=x# 使用 coolwarm 色彩映射plt.scatter(x,y,c=y,cmap='coolwarm')plt.colorbar(label='how2matplotlib.com')plt.title('Coolwarm Colormap Example')plt.axhline(y=0,color='k',linestyle='--')plt.axvline(x=0,colo...
>>> plt.scatter(x,y,c=color,s=size,alpha=0.5) <matplotlib.collections.PathCollection object at 0x0000013F932E2288> >>> plt.colorbar() <matplotlib.colorbar.Colorbar object at 0x0000013F97A22708> >>> plt.show() 1. 2. 3. 4. ...
.map({0:'setosa',1:'versicolor',2:'virginica'})二、散点图 散点图(Scatter Plot)是一种在...
1: mpl-scatter-density 安装 pip install mpl-scatter-density 示例代码 import mpl_scatter_density # adds projection='scatter_density' from matplotlib.colors import LinearSegmentedColormap # "Viridis-like" colormap with white background white_viridis = LinearSegmentedColormap.from_list('white_viridis'...
plt.scatter(x, y, c=colors, s=sizes, alpha=0.3, cmap='viridis') plt.colorbar();# 显示颜色对比条 注意图表右边有一个颜色对比条(这里通过colormap()函数输出),图表中的点大小的单位是像素。使用这种方法,散点的颜色和大小都能用来展示数据信息,...
plt.scatter(x, y, s=sizes, alpha=0.5)plt.show() Result: Try it Yourself » Combine Color Size and AlphaYou can combine a colormap with different sizes of the dots. This is best visualized if the dots are transparent:Example Create random arrays with 100 values for x-points, y-...
0x02 plt.scatter() 用于画散点图。 其中散点的形状参数marker如下: 其中颜色参数c如下: scatter(x, y, 点的大小, 颜色,标记),这是最主要的几个用法,如果括号中不写s= c=则按默认顺序,写了则按规定的来,不考虑顺序 importmatplotlib.pyplot as plt#x,y,大小,颜色plt.scatter([1,2,3,4],[2,4,6...