跳过正文
  1. Teches/
  2. 程序语言/
  3. python/
  4. 程序功能/

画图

·97 字·1 分钟
目录

matplotlib
#

</> python
 1import matplotlib.pyplot as plt
 2def draw(x:list, y:list, titles, fileName, output='./'
 3                   ,lineColor='blue',marker='.',markerfacecolor='white',markeredgecolor='#fd5e0f',fillBetColor='white'):
 4    '''绘图的主要方法
 5
 6    :param x: x轴
 7    :param y: y轴
 8    :param titles: 图片内部标题
 9    :param fileName: 图片文件名称
10    '''
11    fig,ax = plt.subplots(figsize=(20, 6))
12    ax.set_facecolor('white')
13    plt.grid(which='both', color='grey', linestyle='--', alpha=0.5)
14    plt.rcParams['axes.unicode_minus'] = False
15    plt.rcParams['figure.max_open_warning'] = 30
16    plt.plot(x, y,color=lineColor,marker=marker, markerfacecolor=markerfacecolor, markeredgecolor=markeredgecolor)
17    plt.fill_between(x,y,color=fillBetColor)
18    plt.title(label=titles, fontsize=23, loc='left')
19    fig.subplots_adjust(left=0.03, right=1)
20    ax.margins(x=0)
21    plt.xticks(fontsize=10)
22    plt.yticks(fontsize=10)
23    x_num = len(x)//10
24    x_coordinate = x[::x_num]
25    plt.xticks(x_coordinate, x_coordinate)
26    filePath = os.path.join(output, fileName)
27    plt.savefig(f"{filePath}.png", dpi=300)