import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# 生成示例数据
np.random.seed(42)
num_countries = 100
data = pd.DataFrame({
'Country': [f'Country {i}' for i in range(num_countries)],
'GDP per Capita': np.random.lognormal(mean=9, sigma=1, size=num_countries),
'Life Expectancy': np.random.uniform(low=50, high=80, size=num_countries),
'Population': np.random.lognormal(mean=16, sigma=1, size=num_countries),
'Region': np.random.choice(['country1', 'country2', 'country3', 'country4', 'country5'], num_countries)
})
# 设置颜色
palette = sns.color_palette("hls", len(data['Region'].unique()))
# 创建图表
plt.figure(figsize=(14, 10))
# 使用log scale展示GDP per Capita
plt.xscale('log')
# 绘制气泡图
sns.scatterplot(
data=data,
x='GDP per Capita',
y='Life Expectancy',
size='Population',
hue='Region',
palette=palette,
sizes=(20, 2000),
alpha=0.6,
edgecolor='w',
linewidth=0.5
)
# 添加图例和标签
plt.legend(title='World Regions', loc='upper left', bbox_to_anchor=(1, 1), borderaxespad=0)
plt.xlabel('GDP per Capita (log scale)')
plt.ylabel('Life Expectancy at Birth (years)')
plt.title('Gapminder World Map 2030\nMore money often leads to longer lives (i.e. better health).')
# 展示图表
plt.grid(True, which="both", ls="--", linewidth=0.5)
plt.show()
没有合适的资源?快使用搜索试试~ 我知道了~
使用python绘制好看的箱形图、柱状图、散点图
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共6个文件
py:3个
png:2个
jpg:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
0 下载量 139 浏览量
2024-05-26
20:28:27
上传
评论
收藏 148KB ZIP 举报
温馨提示
使用python绘制好看的箱形图、柱状图、散点图
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 6 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/84006f830a514856be7bd23e36377800_weixin_45325693.jpg!1)
今天不想Debug
- 粉丝: 5059
- 资源: 3
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)