Allen's blog Allen's blog
首页
面经
算法 (opens new window)
分类

Allen

前端CV工程师
首页
面经
算法 (opens new window)
分类
  • 包管理工具conda

  • matplotlib绘图

    • matplotlib绘制曲线并输出矢量图
  • 常用系统知识

  • 一些问题及解决方案

  • python
  • matplotlib绘图
Allen
2023-02-16

matplotlib绘制曲线并输出矢量图

参考文章:

  • Matplotlib 绘图原理总结,18 种绘图常用的技 (opens new window)

  • Python_matplotlib 保存矢量图 (opens new window)

  • matplotlib 显示中文的四种方法 (opens new window)

  • matplotlib show, ion, ioff, clf, pause 的作用 (opens new window)

  • Python 列表推导式(更有风格的 Python 代码写法) (opens new window)

  • 【Python】np.linspace 用法介绍 (opens new window)

  • matplotlib 显示特殊符号(gamma,alpha,beta) (opens new window)

  • Python Matplotlib 折线图 线条颜色和样式 (opens new window)

  • 如何在 Matplotlib 中设置图形标题和坐标轴标签字体大小? (opens new window)

    代码:

import matplotlib.pyplot as plt
import numpy as np
# 显示中文
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['FangSong']
mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题

# 设置字体大小
parameters = {'axes.labelsize': 20, 'axes.titlesize': 20, 'legend.fontsize':14}
plt.rcParams.update(parameters)

fig = plt.figure()  # an empty figure with no axes
# fig.suptitle('No axes on this figure')  # Add a title so we know which it is

# fig, ax_lst = plt.subplots(1, 1)
plt.xlim(left = 0, right = 5)
plt.ylim(bottom = 0, top = 5)
plt.xlabel('奇异值', fontsize=20)
plt.ylabel('函数值', fontsize=20)

x = np.linspace(0, 5, 100)
y_r_0_1 = [1.1 * _x / (0.1 + _x) for _x in x ]
y_r_0_5 = [1.5 * _x / (0.5 + _x) for _x in x ]
y_r_1_0 = [2 * _x / (1 + _x) for _x in x ]
y_nuclear = [_x for _x in x ]
y_rank = [1 for _x in x ]

plt.plot(x, y_r_0_1, 'm')
plt.plot(x, y_r_0_5, 'g')
plt.plot(x, y_r_1_0, 'r')
plt.plot(x, y_nuclear, 'c')
plt.plot(x, y_rank, 'tan')
plt.legend(['$\gamma$=0.1', '$\gamma$=0.5', '$\gamma$=1', '核范数', '秩'], fontsize=14)
fig.show()
plt.pause(3)

fig.savefig('./comparison.pdf',dpi=600)
fig.savefig('./comparison.png',dpi=600)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
上次更新: 2023/12/16, 09:22:46
conda常用命令
python os.path路径

← conda常用命令 python os.path路径→

最近更新
01
rollup使用配置文件rollup.config.ts打包
12-08
02
package.json导出类型
12-08
03
关键问题方案
11-17
更多文章>
Theme by Vdoing | Copyright © 2023-2023 Allen | Github
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式