Python-Matplotlib

引入模块

import matplotlib.pyplot as plt

线型

颜色
标记颜色
bblue(蓝色
ccyan(某种蓝色,偏绿)
ggreen(绿色)
kblack(黑色)
mmagenta(紫色)
rred(红色)
wwhite(白色)
yyellow(黄色)

图片来源
这里写图片描述

线型
标记线型
-实线
短线
-.点划线
虚点线
点型
标记点型
.点标记
,像素点标记
o圆标记
v下三角
^上三角
<左三角
>右三角
1下风车
2上风车
3左风车
4右风车
s正方形
p五边形
*星标记
h竖六边形
H横六边形
d方块形
|竖线
_切线
+加号形
x叉形

设置x, y

方法一, 简单公式法
from matplotlib import pyplot as plt
import numpy as np
# ----- ----- 简单公式法 ----- ----- #
x = np.arange(0, 1, 0.1) 
y = 2x+1             
plt.plot(x, y, 'r')
# ----- ----- -------- ----- ----- #
plt.show()
方法二, 简单函数法
from matplotlib import pyplot as plt
import numpy as np
# ----- ----- 简单函数法 ----- ----- #
x = np.arange(0, 1, 0.1) 

def y(x):
    return 2x+1

plt.plot(x, y(x), 'r')
# ----- ----- -------- ----- ----- #
plt.show()
方法三, 列表法
from matplotlib import pyplot as plt
# ----- ----- 列表法 ----- ----- #
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
plt.plot(x, y, 'r')
# ----- ----- ----- ----- ----- #
plt.show()

简单画图

最简单的代码
from matplotlib import pyplot as plt

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
# ----- ----- 最简单的画图代码 ----- ----- #
plt.plot(x, y, 'r')
# ----- ----- ------------- ----- ----- #
plt.show()
有误差bar的图
from matplotlib import pyplot as plt

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
yerr = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
# ----- ----- 纵向等宽误差bar ----- ----- #
plt.errorbar(x, y, yerr=yerr, fmt='ro')
# ----- ----- ------------- ----- ----- #
plt.show()

作图

# ----- ----- 引入相关模块 ----- ----- #
from matplotlib import pyplot as plt
import numpy as np
# ===== ===== ========== ===== ===== #
# ----- ----- 设置x,y ----- ----- #
x = np.arange(0, 10, 0.1)
y = 2x+1
# ===== ===== ====== ===== ===== #
# ----- ----- 画图 ----- ----- #
l1, = plt.plot(x, y, 'r')
# ===== ===== === ===== ===== #
# ----- ----- 设置坐标轴名称 ----- ----- #
plt.xlabel('x')
plt.ylabel(r"$A^p_1(x)$")
# ===== ===== =========== ===== ===== #
# ----- ----- 设置坐标轴的取值范围 ----- ----- #
plt.xlim((0, 12))
plt.ylim((022])
# ===== ===== ================= ===== ===== #
# ----- ----- 设置坐标轴刻度间隔 ----- ----- #
plt.xticks(np.linspace(-1, 1, 5))
plt.yticks([0, 0.5], ['$minimum$', 'normal'])
# ===== ===== =============== ===== ===== #
# ----- ----- 设置坐标轴scale ----- ----- #
plt.xscale('log')
# ===== ===== ============= ===== ===== #
# ----- ----- 设置图例 ----- ----- #
plt.legend(handles = [l1, ], labels = ['a', ], loc = 'best')
# ===== ===== ============= ===== ===== #
# ----- ----- 图中注释 ----- ----- #
plt.text(2, 0.65, r'$\cos(2 \pi t) \exp(-t)$', fontdict=font)
# ===== ===== ======= ===== ===== #
# ----- ----- 显示图片 ----- ----- #
plt.show()
# ===== ===== ======= ===== ===== #
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值