matplotlib

官网

建议学习过程:

  1. 只看 官网教程-Introductory 了解基本语法和概念
  2. 使用时在 官网示例 中找类似的,然后在 官网API 中查阅并设置属性

matplotlib_第1张图片

Figure图形:plt.figure

【axis:坐标轴】
【axes:坐标系,axis的复数形式】
【编码时,不会直接出现axis的表示,单个axes简写为ax,多个axes简写为axs】
Axes坐标系:fig.subplots
Title题目:ax.set_title
Grid网格:ax.grid
Spine样条线:ax.spines
Legend图例:ax.legend

折线线:ax.plot
散点图:ax.scatter
条形图:ax.bar
横条图:ax.barh
饼图:ax.pie
直方图:ax.hist
Step阶梯图:ax.step

x Axis X轴:ax.xaxis
y Axis Y轴:ax.yaxis
Major tick主刻度:ax.xaxis/yaxis.set_major_locator
Major tick label主刻度标签:ax.xaxis/yaxis.set_major_formatter
Minor tick次刻度:ax.xaxis/yaxis.set_minor_locator
Minor tick label次刻度标签:ax.xaxis/yaxis.set_minor_formatter

# 导入库
import matplotlib as mlp
import matplotlib.pyplot as plt
import numpy as np
from numpy import e, log, exp, square

# 设置 中文字体 字体大小
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.rcParams['font.size'] = 12

# 无坐标系图 一个坐标系图 4=2*2个坐标系图
# 常用参数:figsize layout
fig = plt.figure()
fig, ax = plt.subplots()
fig, axs = plt.subplots(2, 2)

# 折线图/散点图
# 常用参数:label color linewidth linestyle
# (仅限散点图) 点大小s, 点内颜色facecolor, 点边颜色edgecolor
ax.plot([1, 2, 3, 4], [1, 4, 2, 3])
ax.scatter([1, 2, 3, 4], [1, 4, 2, 3])

# X轴标签 Y轴标签 标题
# 可选参数 fontsize=14 color='red'
ax.set_xlabel('x label')
ax.set_ylabel('y label')
ax.set_title("Simple Plot")

# 显示图例 显示网格
ax.legend()
ax.grid(True)

# 指定位置放置文本(无箭头)
ax.text(75, .025, r'$\mu=115,\ \sigma=15$')
# 指定位置放置标注(有箭头,删除arrowprops后无箭头)
ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5), arrowprops=dict(facecolor='black', shrink=0.05))

# 设置X轴的显示范围
ax.set_xlim(-2, 2)
# x轴显示 ['zero', '30', 'sixty', '90']
ax.set_xticks(np.arange(0, 100, 30), ['zero', '30', 'sixty', '90'])
# x轴显示 [-1.5, 0, 1.5] 3个数
ax.set_xticks([-1.5, 0, 1.5])

# 显示图表
fig.show()

你可能感兴趣的:(Python基础,matplotlib,python,开发语言)