【无标题】

import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import numpy as np
import pandas as pd
plt.rcParams['font.sans-serif'] = ['SimHei']   # 显示中文标签
plt.rcParams['axes.unicode_minus'] = False   # 正常显示负号
print("Done")
Done
ex1 = pd.read_csv('./data/layout_ex1.csv')
ex1.head()
TimeTemperature
01981-0117.712903
11981-0217.678571
21981-0313.500000
31981-0412.356667
41981-059.490323
fig, axs = plt.subplots(2,5,figsize=(20,5),sharex=True,sharey=True)
fig.suptitle('墨尔本1981年至1990年月温度曲线',size=20)

index = 0
for i in range(2):
    for j in range(5):
        axs[i][j].plot(np.arange(1,13),ex1['Temperature'].values[index*12:(index*12+12)],'o-')
        axs[i][j].set_title('%s年'%ex1['Time'].values[index][:4])
        axs[i][j].xaxis.set_major_locator(ticker.MultipleLocator(1)) #把横坐标设置为1的倍数
        axs[i][j].yaxis.set_major_locator(ticker.MultipleLocator(5)) #把纵坐标设置为5的倍数
        if j==0 :
            axs[i][j].set_ylabel('气温')
        index += 1
fig.tight_layout()

在这里插入图片描述

data_x, data_y = np.random.randn(2, 150)

fig = plt.figure(figsize = (6, 6))
fig.tight_layout()
gs = fig.add_gridspec(2, 2, width_ratios = [5, 1], height_ratios = [1, 5],
                      wspace = 0.05, hspace = 0.05)

ax = fig.add_subplot(gs[1, 0])
ax_histx = fig.add_subplot(gs[0, 0], sharex = ax)
ax_histy = fig.add_subplot(gs[1, 1], sharey = ax)

ax.scatter(data_x, data_y)
ax_histx.hist(data_x, 10, rwidth = 0.9)
ax_histy.hist(data_y, 10, rwidth = 0.9, orientation = 'horizontal')

ax.grid(True)
ax.set_xlabel('my_data_x', fontsize = 8)
for label in ax.xaxis.get_ticklabels():
    label.set_size(8)
ax.set_ylabel('my_data_y', fontsize = 8)
for label in ax.yaxis.get_ticklabels():
    label.set_size(8)
ax_histx.axis('off')
ax_histy.axis('off')

plt.show()

在这里插入图片描述


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值