matplotlib 画分割子图

效果图
请添加图片描述

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

FONT_SIZE = 18
COLORS = ["#468de4", 'orange', 'green', '#e44a44', 'purple', 'grey']

fig = plt.figure(figsize=(14,6))
ax1  = plt.subplot(121)
ax21 = fig.add_subplot(4, 2, (2, 6))
ax22 = plt.subplot(428, sharex=ax21)

# 4 landmarks 1 agent
ax1.set_title("sin", fontsize=FONT_SIZE)
ax1.grid()
ax1.set_xlabel('x_label', fontdict={'size':FONT_SIZE})
ax1.set_ylabel('y_label', fontdict={'size':FONT_SIZE})
ax1.tick_params(labelsize=FONT_SIZE)

data_x = np.arange(100) / 10.
data_y = np.sin(data_x)
ax1.plot(data_x, data_y, label='sin', c=COLORS[0])

# 4 landmarks 1 agent
ax21.set_title("cos", fontsize=FONT_SIZE)
ax21.tick_params(labelsize=FONT_SIZE)
ax21.spines['bottom'].set_visible(False)
ax21.tick_params(labeltop=False, labelbottom=False)  # don't put tick labels at the top
ax21.tick_params(top=False, right=False)  # don't put tick labels at the top
ax21.grid()
ax21.set_ylim(0.45, 1.) 
ax22.set_ylim(-1., -0.55) 

ax22.set_xlabel('x_label', fontdict={'size':FONT_SIZE})
ax22.tick_params(labelsize=FONT_SIZE)
ax22.spines['top'].set_visible(False)
ax22.xaxis.tick_bottom()
ax22.grid()

fig.subplots_adjust(hspace=0.05)


kwargs = dict(marker=[(-1, -.5), (1, .5)], markersize=12,
              linestyle="none", color='k', mec='k', mew=1, clip_on=False)
ax21.plot([0, 1], [0, 0], transform=ax21.transAxes, **kwargs)
ax22.plot([0, 1], [1, 1], transform=ax22.transAxes, **kwargs)

data_y = np.cos(data_x)
ax21.plot([], [], label='sin', c=COLORS[0])
ax21.plot(data_x, data_y, label='cos', c=COLORS[1])
ax22.plot(data_x, data_y, label='cos', c=COLORS[1])

ax21.legend(ncol=2, loc='center', bbox_to_anchor=(-0.1,1.14), fontsize=12, columnspacing=0.25)

plt.subplots_adjust(left=0.09, right=0.98)
plt.savefig('test.pdf') # vector img
plt.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值