1.上一章绘制一幅最简单的图像,这一章介绍figure的详细用法,figure用于生成图像窗口的方法,并可以设置一些参数
2.先看此次生成的图像:
3.代码(代码中有详细的注释)
# -*- encoding:utf-8 -*- # Copyright (c) 2015 Shiye Inc. # All rights reserved. # # Author: ldq <liangduanqi@shiyejinrong.com> # Date: 2019/2/13 9:47 import matplotlib.pyplot as plt import numpy as np import pandas as pd x = np.linspace(-3, 3 ,50) y1 = 2 * x +1 y2 = x ** 2 plt.figure(num="方程曲线", figsize=(5, 5), dpi=100, facecolor="#e9e7ef", edgecolor='#827100') ''' 用于设置窗口的参数 num:窗口名称 figsize:坐标大小 dpi:分辨率 facecolor:窗口颜色 edgecolor:(不清楚) ''' plt.plot(x, y1) plt.plot(x, y2, color="#003300", linewidth=2.0, linestyle='-.') ''' color:线段颜色 linewidth:线段宽度 linestyle:线段类型(共4种,请看下面在源码里找到的) ls_mapper = {'-': 'solid', '--': 'dashed', '-.': 'dashdot', ':': 'dotted'} ''' plt.show()
参考文章地址:https://morvanzhou.github.io/tutorials/data-manipulation/plt/2-2-figure/