Seaborn Scatter Plot与颜色渐变

时间:2016-05-22 19:54:52

标签: python matplotlib plot seaborn data-science

我希望使用Seaborn Plot随时间关联2个变量co2avg_tmp。我想要一个散点图,X轴为year,Y轴为co2avg_tmp为渐变色标(较暗意味着较高的温度)。

我能用matplotlib这样做:

df.plot.scatter(x='year', y='co2', c='avg_tmp', s=100)

enter image description here

这个情节的seaborn等价物是什么。这里的示例数据: https://gist.github.com/raghothams/790eaa3fe7fea034bc687b786eda8995

1 个答案:

答案 0 :(得分:1)

您可以为avg_tmp提供渐变颜色。因此,为此使用带有调色板参数的seaborn scatter plot函数sns.scatterplot()。

在这里,我正在显示带有“数据框”提示的散点图,但您可以用数据集变量代替

hue = "avg_tmp"
size = "avg_tmp" # for increase the size of points

-

# import libaries
import seaborn as sns # for data visualization

# load tips dataset from GitHub seaborn repository
tips_df = sns.load_dataset("tips")

#create seaborn scatter plot
sns.scatterplot(x = "tip", y = "total_bill", data = tips_df, hue = "sex", 
                size ="sex", sizes = (100, 300), palette = "gist_gray")

输出>>>

enter image description here

调色板值:Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap, CMRmap_r, Dark2, Dark2_r, GnBu, GnBu_r, Greens, Greens_r, Greys, Greys_r, OrRd, OrRd_r, Oranges, Oranges_r, PRGn, PRGn_r, Paired, Paired_r, Pastel1, Pastel1_r, Pastel2, Pastel2_r, PiYG, PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr, PuOr_r, PuRd, PuRd_r, Purples, Purples_r, RdBu, RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu, RdYlBu_r, RdYlGn, RdYlGn_r, Reds, Reds_r, Set1, Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral, Spectral_r, Wistia, Wistia_r, YlGn, YlGnBu, YlGnBu_r, YlGn_r, YlOrBr, YlOrBr_r, YlOrRd, YlOrRd_r, afmhot, afmhot_r, autumn, autumn_r, binary, binary_r, bone, bone_r, brg, brg_r, bwr, bwr_r, cividis, cividis_r, cool, cool_r, coolwarm, coolwarm_r, copper, copper_r, cubehelix, cubehelix_r, flag, flag_r, gist_earth, gist_earth_r, gist_gray, gist_gray_r, gist_heat, gist_heat_r, gist_ncar, gist_ncar_r, gist_rainbow, gist_rainbow_r, gist_stern, gist_stern_r, gist_yarg, gist_yarg_r, gnuplot, gnuplot2, gnuplot2_r, gnuplot_r, gray, gray_r, hot, hot_r, hsv, hsv_r, icefire, icefire_r, inferno, inferno_r, jet, jet_r, magma, magma_r, mako, mako_r, nipy_spectral, nipy_spectral_r, ocean, ocean_r, pink, pink_r, plasma, plasma_r, prism, prism_r, rainbow, rainbow_r, rocket, rocket_r, seismic, seismic_r, spring, spring_r, summer, summer_r, tab10, tab10_r, tab20, tab20_r, tab20b, tab20b_r, tab20c, tab20c_r, terrain, terrain_r, twilight, twilight_r, twilight_shifted, twilight_shifted_r, viridis, viridis_r, vlag, vlag_r, winter, winter_r