美文网首页
matplotlib 画图

matplotlib 画图

作者: 球果假水晶蓝 | 来源:发表于2022-02-28 18:36 被阅读0次
# !usr/bin/env python
# -*- coding:utf-8 -*-
"""
@FileName: 模板
@Time: 2022/2/28,10:41
@Name: Zhang Yixing
"""
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt

plt.figure(figsize=(4, 3), dpi=100)
x_data = [11, 12, 13, 14, 15, 16, 17]
y_data = [58, 60, 63, 71, 84, 90, 107]
y_data2 = [40, 54, 51, 58, 56, 59, 62]

ln1 = plt.plot(x_data, y_data, label='y1', color='blue', linewidth=1.0)
ln2 = plt.plot(x_data, y_data2, label='y2', color='blue', linewidth=2.0, linestyle='--')
plt.title("title")  # 图片标题
plt.xlabel("x lable", loc="center")  # 设置X轴名称以及位置

plt.ylabel("y lable", loc="center")

# plt.axis([0, 6, 0, 20]) 语法为axis[xmin, xmax, ymin, ymax]
# 一种设置坐标轴的办法
plt.xticks(np.arange(10, 20, 2), ['10', '12', '14', '16', '18'])
# 另一种设置坐标轴的办法
plt.ylim([0, 120])
plt.yticks(np.linspace(0, 120, 12, endpoint=True))

# 添加注释 参数名xy:箭头注释中箭头所在位置,参数名xytext:注释文本所在位置,
# arrowprops在xy和xytext之间绘制箭头, shrink表示注释点与注释文本之间的图标距离
plt.annotate(text='local max', xy=(14, 60), fontsize=1, xytext=(16, 65), weight='bold', 
             arrowprops=dict(facecolor="red",
                             headlength=4, headwidth=4, width=2))

plt.grid(True)  # 显示网格线

# matplotlib中各种图案都是以锚点保存, 使用mpl可以设置pdf图片文字以字体形式保存
mpl.rcParams['pdf.fonttype'] = 42

# 将右边和上边的边框去除
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')

# 加上图例,以及边缘的颜色,内部的颜色
plt.legend(loc='upper left', edgecolor='None', facecolor='none')

# python使用matplotlib的savefig保存时图片保存不完整的问题
plt.savefig('模板.pdf', dpi=300, bbox_inches='tight')
plt.show()
image.png

相关文章

  • Python之MatPlotLib使用教程

    1.Matplotlib简介 Matplotlib是非常强大的python画图工具 Matplotlib可以画图线...

  • 【python实战】matplotlib绘图(二)

    【python实战】matplotlib绘图(一) 话不多说,接着画图,不得不说,matplotlib画图,写的代...

  • 深入详解matplotlib画图进阶

    一、matplotlib的画图步骤以及图形结构 前面我已经写过关于matplotlib的画图架构方面的问题,...

  • matplotlib 画图

    1、https://blog.csdn.net/helunqu2017/article/details/78650...

  • matplotlib 画图

    Matplotlib for presenting results

  • matplotlib画图

    简单的画图操作 这里画的是bp算法迭代过程的output图

  • matplotlib画图

    要有这种思路 alpha透明度,stacked是否允许堆叠,bins分组数量,orientation画图形态,横向

  • matplotlib画图

    参考https://www.cnblogs.com/xubing-613/p/5895948.html 使用左键移...

  • 画图MATPLOTLIB

    Figure:整个画布对象。我们所有的绘图操作都是在Figure对象上操作的,不论是单个图表还是多子图。 Axes...

  • matplotlib 画图

    折线图 fig = plt.figure(figsize=(20,10), dpi=80) 或者fig, ax =...

网友评论

      本文标题:matplotlib 画图

      本文链接:https://www.haomeiwen.com/subject/oyalrrtx.html