Task3:用极坐标系绘制玫瑰图&散点图和边际分布图的绘制

知识速记:
tight_layout():调整子图的相对大小使字符不会重叠
subplot():第一个数字为行,第二个为列,不传入时默认值都为1
一、用极坐标系绘制玫瑰图

import numpy as np
import pandas as pd
fig = plt.figure(figsize=(10, 6))
ax = plt.subplot(111, projection='polar')
ax.set_theta_direction(-1)  
ax.set_theta_zero_location('N')
r = np.arange(100, 800, 20)
theta = np.linspace(0, np.pi * 2, len(r), endpoint=False)
ax.bar(theta, r, width=0.18, color=np.random.random((len(r), 3)),
       align='edge', bottom=100)
ax.text(np.pi * 3 / 2 - 0.2, 90, '鲍凯悦', fontsize=14)  
for angle, height in zip(theta, r):
    ax.text(angle + 0.03, height + 120, str(height), fontsize=height / 80)
plt.axis('off')  
plt.tight_layout()  
plt.show()

在这里插入图片描述
二、用 np.random.randn(2, 150) 生成一组二维数据,使用两种非均匀子图的分割方法,做出该数据对应的散点图和边际分布图

x,y = np.random.randn(2, 150)
fig = plt.figure(figsize=(4, 4))
spec = fig.add_gridspec(nrows=2, ncols=2, width_ratios=[5, 1], height_ratios=[1, 6])
ax = fig.add_subplot(spec[1, 0])
ax.grid(True)
ax.scatter(x, y)
ax.set_xlabel('my_data_x')
ax.set_ylabel('my_data_y')
ax = fig.add_subplot(spec[0, 0])
ax.hist(x, bins=10)
plt.axis('off')     
ax = fig.add_subplot(spec[1, 1])
ax.hist(y, bins=10, orientation='horizontal')    # orientation='horizontal'使得条形为水平方向
plt.axis('off')    
plt.tight_layout()
plt.subplots_adjust(wspace=0, hspace=0)
plt.savefig('思考题.png')

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值