python - 对加权散点图使用颜色强度而不是气泡大小
问题描述
有什么方法可以使用颜色强度而不是气泡大小来绘制加权散点图?我已经在网上搜索了几个小时的解决方案,但仍然没有找到。我使用以下企鹅数据进行说明。
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
penguins_data="https://raw.githubusercontent.com/datavizpyr/data/master/palmer_penguin_species.tsv"
penguins_df = pd.read_csv(penguins_data, sep="\t")
sns.set_context("talk", font_scale=1.1)
plt.figure(figsize=(10,6))
sns.scatterplot(x="culmen_length_mm",
y="culmen_depth_mm",
size="body_mass_g",
sizes=(20,500),
alpha=0.5,
data=penguins_df)
# Put the legend out of the figure
plt.legend(bbox_to_anchor=(1.01, 1),borderaxespad=0)
# Put the legend out of the figure
#plt.legend(bbox_to_anchor=(1.01, 0.54), borderaxespad=0.)
plt.xlabel("Culmen Length (mm)")
plt.ylabel("Culmen Depth (mm)")
plt.title("Bubble plot in Seaborn")
plt.tight_layout()
plt.savefig("Bubble_plot_size_range_Seaborn_scatterplot.png",
format='png',dpi=150)
气泡图最小的气泡对应最小的体重,最大的气泡对应最大的体重。但是,我需要加权散点图的颜色强度。例如,较深的颜色表示它出现的频率较高,而较浅的颜色表示它出现的频率较低。任何使用 Stata(首选)、Python 或 R 的建议都将受到高度赞赏。
我在 Stata 中找到了类似这样的东西,但是我的数据结构完全不同,所以它不起作用。
解决方案
您是否考虑过在数据框中为颜色创建一个新列,您可以在其中自行调整 Alpha 通道?
之后,您可能可以从这个问题中使用它作为颜色列作为标记的色调。
推荐阅读
- python-3.x - 我怎样才能使我的文件是可点击的功能
- android - Android ImageView setImageResource 在 OS 6.0 中不起作用
- javascript - ForEach 语句中的 MVC Javascript
- javascript - "click(e=>{" 和 "click(function(e){" 之间的区别
- node.js - 在 npm 中使用目录并将它们指向 src?
- z3 - 从具有字符串文字的公式中提取 Craig 的插值
- c# - 从 using 块内返回时是否会处理内存流
- c# - 如何为 ASPState 数据库指定自定义名称?
- c# - Azure Functions 使用两个输出 blob 调整 blob 大小
- leaflet - 传单上下文菜单+标记拖动