pandas 山脊图
时间: 2023-10-04 07:14:03 浏览: 71
要绘制pandas的山脊图,你可以使用以下代码:
```python
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
df = pd.read_csv('./data/film.csv')
languages = ['English', 'Hindi', 'Spanish', 'French', 'Italian', 'Portuguese']
df_filtered = df[df['Language'].isin(languages)]
sns.set_theme(rc={"axes.facecolor": (0, 0, 0, 0), 'figure.facecolor':'#000000', 'axes.grid':False})
g = sns.FacetGrid(df_filtered, row='Language', hue='Language', aspect=15, height=.5, palette='colorblind')
g.map(sns.kdeplot, 'IMDB Score', clip_on=False, fill=True, alpha=0.75, linewidth=1.5)
g.map(plt.axhline, y=0, color='#ffffff', lw=2)
g.set_titles("")
g.set(yticks=[], xticks=[], ylabel="", xlabel="")
g.despine(bottom=True, left=True)
plt.savefig('ridgeplot.png', facecolor='#000000')
```
这段代码首先导入必要的库,然后加载数据集并根据语言筛选出需要的数据。接下来,我们使用seaborn设置绘图风格,并创建一个FacetGrid对象用于绘制子图。在子图上使用`kdeplot`函数绘制每种语言对应的IMDB评分的山脊图,并使用`axhline`函数添加白色的水平线。最后,我们设置子图的标题、坐标轴标签等,并保存图像为'ridgeplot.png'。
请注意,你需要替换代码中的数据集路径和保存的图像名称以适应你的实际情况。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [数据可视化之使用Seaborn绘制山脊图](https://blog.csdn.net/sgzqc/article/details/121911883)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [在Seaborn的山脊图中添加右侧的yaxis](https://blog.csdn.net/weixin_35338620/article/details/113495568)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文