数据可视化教程作业打卡-第三回:布局格式定方圆

教程链接

https://github.com/datawhalechina/fantastic-matplotlib

https://gitee.com/zhang35/fantastic-matplotlib/blob/main/第三回:布局格式定方圆.ipynb

作业

1. 墨尔本1981年至1990年的每月温度情况

ex1 = pd.read_csv('data/layout_ex1.csv')
ex1.head()

	Time	Temperature
0	1981-01	17.712903
1	1981-02	17.678571
2	1981-03	13.500000
3	1981-04	12.356667
4	1981-05	9.490323
  • 请利用数据,画出如下的图:
fig, axes = plt.subplots(2, 5, figsize=(18, 4), sharex=True, sharey=True)
year = 1981
fig.suptitle('墨尔本1981年至1990年月温度曲线', size=20)
for i in range(2):
    axes[i, 0].set_ylabel("气温")
    for j in range(5):
        ax = axes[i, j]
        ax.set_title("%d年" % year)
        year += 1
        data_start = (i * 5 + j) * 12
        ax.plot(range(1, 13), ex1.iloc[data_start : data_start + 12]['Temperature'], marker='*')
        ax.set_xticks(range(1, 13))
fig.tight_layout()

在这里插入图片描述

2. 画出数据的散点图和边际分布

  • np.random.randn(2, 150) 生成一组二维数据,使用两种非均匀子图的分割方法,做出该数据对应的散点图和边际分布图
data = np.random.randn(2, 150)
fig = plt.figure(figsize=(6, 6))
spec = fig.add_gridspec(nrows=5, ncols=5, width_ratios=[1]*5, height_ratios=[1] * 5)

ax = fig.add_subplot(spec[1:5, :4])
ax.grid()
ax.set_xlabel('my_data_x')
ax.set_ylabel('my_data_y')
ax.scatter(data[0], data[1])

ax2 = fig.add_subplot(spec[:1, :4])
# ax2.get_xaxis().set_visible(False)
# ax2.get_yaxis().set_visible(False)
ax2.axis('off')
# bins = np.arange(-2.8, 3.7, 0.5)
# ax.hist(data[0], bins, alpha=0.5, rwidth=0.8)
ax2.hist(data[0], rwidth=0.8) # hist默认的bin=10

ax3 = fig.add_subplot(spec[1:5, 4:])
ax3.axis('off')
ax3.hist(data[1], rwidth=0.8, orientation='horizontal')

fig.tight_layout()
plt.show()

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值