如何在 matplotlib 图表中循环遍历颜色和线型?
要循环遍历 matplotlib 图表中的颜色和线型,我们可以采取以下步骤。
步骤
设置图表大小,并调整子图表之间、周围的间距。
使用颜色和线型,设置当前的rcParams。
使用 plot() 方法绘制数据点。
要显示图表,请使用 Show() 方法。
示例
import matplotlib.pyplot as plt
from cycler import cycler
# Set the figure size
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
# Set the rcParams with color or linestyle
plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +
cycler('linestyle', [':', '-.', '-', '--'])))
# Plot the data points
plt.plot([0, 5, 2, 1])
plt.plot([2, 6, 3, 1])
plt.plot([3, 8, 5, 1])
plt.plot([4, 9, 0, 3])
plt.show()输出
它将生成以下输出 −

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP