上述代码我们还展示了怎么根据数值范围(这里以拟合误差范围为例e.min(), e.max())按照给定的colormap图片提取渐变颜色,并在指定图幅位置(bax=fig.add_axes([p1, p2, p3, p4]))放置指定的colorbar。
x=np.linspace(0,10,100)y=np.sin(x)plt.plot(x,y,c=y,cmap='plasma')plt.colorbar()plt.show() Python Copy 8. Colormap与3D图表配合 除了2D图表外,colormap也可以与3D图表配合使用。下面是一个示例代码,展示了如何在3D图表中使用colormap。 importmatplotlib.pyplotaspltimportnumpyasnp fig=plt.figu...
=[2,3,5,7,11]plt.plot(x,y,color='g')plt.show() Python Copy Output: 5. 使用Colormap Colormap是一种将连续数据映射到颜色的方式,常用于绘制热度图等图形。Matplotlib中提供了很多不同的Colormap,可以根据具体需求选择合适的Colormap。 importmatplotlib.pyplotaspltimportnumpyasnp x=np.linspace(0,2*...
def plot_examples(colormaps): """ Helper function to plot data with associated colormap. """ np.random.seed(19680801) data = np.random.randn(30, 30) n = len(colormaps) fig, axs = plt.subplots(1, n, figsize=(n * 2 + 2, 3), layout='constrained', squeeze=False) for [ax, cm...
=plt.subplots(figsize=(4,3),layout='constrained')col=['r','g','b']forxxin[0.25,0.5,0.75]:ax.axvline(xx,color='0.7',linestyle='--')foriinrange(3):ax.plot(np.arange(256)/256,rgba[:,i],color=col[i])ax.set_xlabel('index')ax.set_ylabel('RGB')plt.show()plot_linearmap(c...
plot_color_gradients('Miscellaneous',['flag', 'prism', 'ocean', 'gist_earth', 'terrain','gist_stern', 'gnuplot', 'gnuplot2', 'CMRmap','cubehelix', 'brg', 'gist_rainbow', 'rainbow', 'jet','turbo', 'nipy_spectral', 'gist_ncar'])plt.show() ...
创建colormap 时通常需要以下两步: 使用Normalize 实例或子类将数据数组归一化为 [0 1]之间的数组 使用Colormap 子类的实例进行数据和颜色的映射 模块中提供了以下两个函数创建 colormap: LinearSegmentedColormap所有内置 colormap 实例均由此函数创建,但也可以自定义colormap ...
Matplotlib qualitative colormap visualization example. Image by Author. Rainbow colormaps Rainbow colormaps like hsv are used when a broad range of hues is needed. # Generate cyclic data x = np.linspace(0, 2 * np.pi, 500) y = np.sin(x) # Create a plot with rainbow colormap plt.scat...
ax2.plot([1,2,3],[1,2,3]) 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 4.网格: import matplotlib.pyplot as plt import numpy as np y = np.arange(1,5) plt.plot(y,y*2) plt.grid(True) # 打开网格 plt.grid(color = 'g') # 定制化网格 ...
plt.plot([1,2,3,4],[2,3,4,5]); 二、色彩设置 在matplotlib中,设置颜色有以下几种方式: RGB或RGBA HEX RGB 或 RGBA 灰度色阶 单字符基本颜色 颜色名称 使用colormap设置一组颜色 (一)RGB或RGBA plt.style.use('default') # 颜色用[0,1]之间的浮点数表示,四个分量按顺序分别为(red, green, blue...