在Python中,可以使用以下方法设置绘图的颜色:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [1, 4, 9, 16]
plt.plot(x, y, color='red') # 设置线条颜色为红色
plt.show()
color
参数。import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [1, 4, 9, 16]
plt.plot(x, y, color='#FF0000') # 设置线条颜色为红色
plt.show()
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [1, 4, 9, 16]
plt.plot(x, y, color=(1, 0, 0)) # 设置线条颜色为红色
plt.show()
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [1, 4, 9, 16]
plt.plot(x, y, color='r') # 设置线条颜色为红色
plt.show()
这些方法适用于大多数绘图函数,如plot()
、scatter()
、bar()
等。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
相关推荐:python设置颜色的方法是什么