x=np.linspace(0,10,100)y1=np.sin(x)y2=np.cos(x)plt.plot(x,y1,color='blue',alpha=0.5)# 修改线条透明度为0.5plt.plot(x,y2,color='red',alpha=0.8)# 修改线条透明度为0.8plt.show() Python Copy Output: 在这个示例中,第一条线的透明度为0.5,第二条线
frommatplotlib.patchesimportRectangleimportmatplotlib.pyplotaspltimportmatplotlib.colorsasmcolorsdefplot_colortable(colors,sort_colors=True,emptycols=0):cell_width=212cell_height=22swatch_width=48margin=12# Sort colors by hue, saturation, value and name.ifsort_colorsisTrue:by_hsv=sorted((tuple(mcolors...
plt.plot(x, pdf(x, mu, sigma), color = str(.15*(i+1))) plt.plot(x, pdf(x, 0., 1.), color = 'k') plt.plot(x, pdf(x, 0.2, 1.), color = '#00ff00') plt.plot(x, pdf(x, 0.4, 1.), color = (0.9,0.9,0.0)) plt.plot(x, pdf(x, 0.4, 1.), color = (0.9,...
[2, 3, 5, 7, 11] colors = ['red', 'blue', 'green', 'cyan', 'magenta'] # 使用颜色列表绘制散点图 plt.scatter(x_values, y_values, s=100, c=colors, marker='o') # 添加标题和轴标签 plt.title('Color List Scatter Plot') plt.xlabel('X-axis') plt.ylabel('Y-axis') # 显示...
title('Color Plot Example') plt.xlabel('X Axis') plt.ylabel('Y Axis') # 显示图表 plt.show() 解释 导入库:导入 matplotlib.pyplot 和numpy 库。 生成示例数据:创建一个 10x10 的随机矩阵。 创建颜色图:使用 imshow 函数创建颜色图,并设置颜色映射为 viridis。 添加颜色条:使用 colorbar 函数添加颜色...
x=np.linspace(0,10,100)plt.figure(figsize=(10,6))plt.plot(x,np.sin(x),color='red',alpha=0.3,label='Low Alpha')plt.plot(x,np.cos(x),color='blue',alpha=0.7,label='Medium Alpha')plt.plot(x,np.tan(x),color='green',alpha=1.0,label='Full Alpha')plt.title('Color transparency ...
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 ...
创建色图得本质是上面的逆操作,我们向 ListedColormap 提供颜色规范的列表或数组以创建新的色图。 在这里我们会定义一个辅助函数:plot_examples,该函数将多个色图之一作为输入,创建一些随机数据,并将色图应用于该数据集的图像图。 import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import Li...
plot(x, y, color='green', linestyle='dashed', marker='o',markerfacecolor='blue', markersize=12) kwargs是 Line2D 属性: #coding=utf8'''引用matplotlib.pylot包的两种方法:import matplotlib.pyplot as plt:使用plt对象,如plt.plot()。from pylab import * :使用对象,直接是plot()。引用numpy包。pyl...
黑色),w(白色)# 抛物线x = np.linspace(-5, 5, 50)y = x**2# 画图:设置颜色plt.plot(x,y,c="r")[<matplotlib.lines.Line2D at 0x1d65ba7d990>]第二种方式plt.plot(x,y,color="red")[<matplotlib.lines.Line2D at 0x1d65c0a7190>]# ls:line style 设置样式红色实线plt.plot(x,y,c="...