from matplotlib import pyplot as plt x = [1, 3, 5, 7, 9] y = [2, 4, 6, 8, 10] ''' # 改变线的属性 # 第一种方式,向方法传入关键字参数来指定线型 plt.plot(x, y, linewidth=15) ''' ''' # 第二种方式,对plot()方法调用返回的线条实例(matplotlib.lines.Line2D)使用setter方法 line, = plt.plot(x, y) line.set_linewidth(15) ''' # 第三种方式,setp()方法 lines = plt.plot(x, y) ''' plt.setp(lines, 'linewidth', 15) ''' plt.setp(lines, linewidth=15) # 改变线条的所有属性都包含在matplotlib.lines.Line2D类中 # 调用matplotlib.pyplot.colors()得到matplotlib支持的所有颜色 # HTML十六进制字符串定义颜色值,color = '#eeefff',或者HTML颜色名字'red', 'chartreuse' # 归一化到[0, 1]的RGB元组定义颜色值,color = (0.3, 0.3, 0.4) plt.title('Title in a custom color', color='red') # 通过plt.axes()或者plt.subplot()的axisbg参数,指定坐标轴的背景色 # plt.subplot(111, axisbg='red') plt.axes(axisbg='red') plt.show()
设置图表的线型、属性和格式化字符串
最新推荐文章于 2024-07-23 18:58:03 发布