本文详细介绍如何绘制断裂坐标轴(broken_axis)及图例(legend)设置。
本文速览
image
image
目录
1、x轴坐标轴断裂 or 打断
2、y轴坐标轴断裂 or 打断
3、brokenaxes打断坐标轴
4、图例设置
loc参数详解
断裂坐标轴的原理是在不同子图上绘制同一图,设置子图轴显示范围,去掉子图脊,使得看起来像一张图。
1、x轴坐标轴断裂 or 打断
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(19680801)
pts = np.random.rand(30)*.2
pts[[3, 14]] += 1.8# 将索引为3个和14的元素加1.8处理成两个离散点
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True, dpi=100)
ax1.plot(pts)
ax2.plot(pts)
ax1.set_xlim(0, 10) # 子图1设置y轴范围,只显示部分图
ax2.set_xlim(11, 20) # 子图2设置y轴范围,只显示部分图
ax1.spin