国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

添加數(shù)據(jù)維度并使用Python繪制5D散點圖

這篇具有很好參考價值的文章主要介紹了添加數(shù)據(jù)維度并使用Python繪制5D散點圖。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

大家好,散點圖通常用于比較2個不同特征以確定它們之間的關(guān)系,散點圖也可以添加更多的維度來反映數(shù)據(jù),例如使用顏色、氣泡大小等。在本文中,將介紹如何繪制一個五維的散點圖。

數(shù)據(jù)集:

https://github.com/checkming00/Medium_datasets/blob/main/WH%20Report_preprocessed.csv

添加數(shù)據(jù)維度并使用Python繪制5D散點圖,python可視化,python,開發(fā)語言

?讓我們從二維開始,簡單地看一下Healthy_life_expectancy_at_birthLog_GDP_per_capita的圖:

df.plot.scatter('Healthy_life_expectancy_at_birth', 'Log_GDP_per_capita')

添加數(shù)據(jù)維度并使用Python繪制5D散點圖,python可視化,python,開發(fā)語言

?我們可以看到這2個特征具有很強的正相關(guān)關(guān)系。然后我們可以將year作為我們的三維視覺效果添加到繪圖中:

import matplotlib.pyplot as plt
import numpy as np

plt.figure(figsize=(15, 8))

years = np.sort(df.year.unique())
for i, year in enumerate(years):
    BM = df.year == year
    X = df[BM]['Healthy_life_expectancy_at_birth']
    Y = df[BM]['Log_GDP_per_capita']
    plt.subplot(2, 5, i+1) # 2X5 structure of subplots, at i+1 position
    plt.scatter(X, Y)
    plt.title(year)
    plt.xlim([30, 80]) # x axis range
    plt.ylim([6, 12]) # y axis range
plt.show()
plt.tight_layout()

添加數(shù)據(jù)維度并使用Python繪制5D散點圖,python可視化,python,開發(fā)語言

它顯示了多年來Healthy_life_expectancy_at_birthLog_GDP_per_capita之間的關(guān)系。另一方面,我們可以讓它具有交互性:

def plotyear(year):
    BM = df.year == year
    X = df[BM]['Healthy_life_expectancy_at_birth']
    Y = df[BM]['Log_GDP_per_capita']
    plt.scatter(X, Y)
    plt.xlabel('Healthy_life_expectancy_at_birth')
    plt.ylabel('Log_GDP_per_capita')
    plt.xlim([30, 80])
    plt.ylim([6, 12])
    plt.show()
from ipywidgets import interact, widgets

min_year=df.year.min()
max_year=df.year.max()
interact(plotyear, 
         year=widgets.IntSlider(min=min_year, 
                                max=max_year, step=1, value=min_year))

添加數(shù)據(jù)維度并使用Python繪制5D散點圖,python可視化,python,開發(fā)語言

?

然后我們可以拖動頂部的控制條來更改年份?,F(xiàn)在讓我們把第四個維度Continent作為圖例放入:

continents = df.Continent.unique()

con_colors = dict(zip(continents, ['b', 'g', 'r', 'c', 'm', 'y' ,'k']))
import seaborn as sns

def plotyear_continent(year):
    BM = df.year == year
    sns.scatterplot(data=df[BM], x='Healthy_life_expectancy_at_birth', 
                    y='Log_GDP_per_capita', hue='Continent', palette=con_colors)
    plt.xlabel('Healthy_life_expectancy_at_birth')
    plt.ylabel('Log_GDP_per_capita')
    plt.xlim([30, 80])
    plt.ylim([6, 12])
    plt.legend()
    plt.show()
interact(plotyear_continent, 
         year=widgets.IntSlider(min=min_year, 
                                max=max_year, step=1, 
                                value=round(df.year.mean(),0)))

添加數(shù)據(jù)維度并使用Python繪制5D散點圖,python可視化,python,開發(fā)語言

?

它顯示了不同大洲之間的關(guān)系,將默認年份設(shè)置為2014年(value=round(df.year.mean(),0))。

我們可以在視覺上做得更多的是氣泡的大小。所以我們可以把population作為第五維:

continents = df.Continent.unique()

con_colors = dict(zip(continents, ['b', 'g', 'r', 'c', 'm', 'y' ,'k']))

min_size=df['population'].min()/1000000  # Scale bubble minimum size
max_size=df['population'].max()/1000000  # Scale bubble maximum size

def plotyear_continent_pop(year):
    BM = df.year == year
    sns.scatterplot(data=df[BM], x='Healthy_life_expectancy_at_birth', 
                    y='Log_GDP_per_capita', hue='Continent', 
                    palette=con_colors, size='population', 
                    sizes=(min_size, max_size))
    plt.xlabel('Healthy_life_expectancy_at_birth')
    plt.ylabel('Log_GDP_per_capita')
    plt.xlim([30, 80])
    plt.ylim([6, 12])
    plt.legend()
    plt.show()

interact(plotyear_continent_pop, 
         year=widgets.IntSlider(min=min_year, 
                                max=max_year, step=1, 
                                value=round(df.year.mean(),0)))

添加數(shù)據(jù)維度并使用Python繪制5D散點圖,python可視化,python,開發(fā)語言

?

它顯示了各大洲與氣泡大小作為人口的關(guān)系。

這就是我們制作5D散點圖的方式,它可以盡可能在同一圖像中告訴人們所需要的信息。文章來源地址http://www.zghlxwxcb.cn/news/detail-524216.html

到了這里,關(guān)于添加數(shù)據(jù)維度并使用Python繪制5D散點圖的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包