最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python可視化分析繪制散點(diǎn)圖和邊界氣泡圖

 更新時(shí)間:2022年06月23日 17:14:46   作者:不再依然07  
這篇文章主要介紹了python可視化分析繪制散點(diǎn)圖和邊界氣泡圖,python繪制散點(diǎn)圖,展現(xiàn)兩個(gè)變量間的關(guān)系,當(dāng)數(shù)據(jù)包含多組時(shí),使用不同顏色和形狀區(qū)分

一、繪制散點(diǎn)圖

實(shí)現(xiàn)功能:

python繪制散點(diǎn)圖,展現(xiàn)兩個(gè)變量間的關(guān)系,當(dāng)數(shù)據(jù)包含多組時(shí),使用不同顏色和形狀區(qū)分。

實(shí)現(xiàn)代碼:

import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings(action='once')
plt.style.use('seaborn-whitegrid')
sns.set_style("whitegrid")
print(mpl.__version__)
print(sns.__version__)
def draw_scatter(file):
? ? # Import dataset
? ? midwest = pd.read_csv(file)
? ? # Prepare Data
? ? # Create as many colors as there are unique midwest['category']
? ? categories = np.unique(midwest['category'])
? ? colors = [plt.cm.Set1(i / float(len(categories) - 1)) for i in range(len(categories))]
? ? # Draw Plot for Each Category
? ? plt.figure(figsize=(10, 6), dpi=100, facecolor='w', edgecolor='k')

? ? for i, category in enumerate(categories):
? ? ? ? plt.scatter('area', 'poptotal', data=midwest.loc[midwest.category == category, :],s=20,c=colors[i],label=str(category))
? ? # Decorations
? ? plt.gca().set(xlim=(0.0, 0.1), ylim=(0, 90000),)
? ? plt.xticks(fontsize=10)
? ? plt.yticks(fontsize=10)
? ? plt.xlabel('Area', fontdict={'fontsize': 10})
? ? plt.ylabel('Population', fontdict={'fontsize': 10})
? ? plt.title("Scatterplot of Midwest Area vs Population", fontsize=12)
? ? plt.legend(fontsize=10)
? ? plt.show()
draw_scatter("F:\數(shù)據(jù)雜壇\datasets\midwest_filter.csv")

實(shí)現(xiàn)效果:

二、繪制邊界氣泡圖

實(shí)現(xiàn)功能:

氣泡圖是散點(diǎn)圖中的一種類型,可以展現(xiàn)三個(gè)數(shù)值變量之間的關(guān)系,之前的文章介紹過(guò)一般的散點(diǎn)圖都是反映兩個(gè)數(shù)值型變量的關(guān)系,所以如果還想通過(guò)散點(diǎn)圖添加第三個(gè)數(shù)值型變量的信息,一般可以使用氣泡圖。氣泡圖的實(shí)質(zhì)就是通過(guò)第三個(gè)數(shù)值型變量控制每個(gè)散點(diǎn)的大小,點(diǎn)越大,代表的第三維數(shù)值越高,反之亦然。而邊界氣泡圖則是在氣泡圖添加第四個(gè)類別型變量的信息,將一些重要的點(diǎn)選出來(lái)并連接。

實(shí)現(xiàn)代碼:

import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
from scipy.spatial import ConvexHull
warnings.filterwarnings(action='once')
plt.style.use('seaborn-whitegrid')
sns.set_style("whitegrid")
print(mpl.__version__)
print(sns.__version__)

def draw_scatter(file):
? ? # Step 1: Prepare Data
? ? midwest = pd.read_csv(file)

? ? # As many colors as there are unique midwest['category']
? ? categories = np.unique(midwest['category'])
? ? colors = [plt.cm.Set1(i / float(len(categories) - 1)) for i in range(len(categories))]

? ? # Step 2: Draw Scatterplot with unique color for each category
? ? fig = plt.figure(figsize=(10, 6), dpi=80, facecolor='w', edgecolor='k')

? ? for i, category in enumerate(categories):
? ? ? ? plt.scatter('area','poptotal',data=midwest.loc[midwest.category == category, :],s='dot_size',c=colors[i],label=str(category),edgecolors='black',linewidths=.5)
? ? # Step 3: Encircling
? ? # https://stackoverflow.com/questions/44575681/how-do-i-encircle-different-data-sets-in-scatter-plot
? ? def encircle(x, y, ax=None, **kw): ?# 定義encircle函數(shù),圈出重點(diǎn)關(guān)注的點(diǎn)
? ? ? ? if not ax: ax = plt.gca()
? ? ? ? p = np.c_[x, y]
? ? ? ? hull = ConvexHull(p)
? ? ? ? poly = plt.Polygon(p[hull.vertices, :], **kw)
? ? ? ? ax.add_patch(poly)
? ? # Select data to be encircled
? ? midwest_encircle_data1 = midwest.loc[midwest.state == 'IN', :]
? ? encircle(midwest_encircle_data1.area,midwest_encircle_data1.poptotal,ec="pink",fc="#74C476",alpha=0.3)
? ? encircle(midwest_encircle_data1.area,midwest_encircle_data1.poptotal,ec="g",fc="none",linewidth=1.5)
? ? midwest_encircle_data6 = midwest.loc[midwest.state == 'WI', :]
? ? encircle(midwest_encircle_data6.area,midwest_encircle_data6.poptotal,ec="pink",fc="black",alpha=0.3)
? ? encircle(midwest_encircle_data6.area,midwest_encircle_data6.poptotal,ec="black",fc="none",linewidth=1.5,linestyle='--')
? ? # Step 4: Decorations
? ? plt.gca().set(xlim=(0.0, 0.1),ylim=(0, 90000),)
? ? plt.xticks(fontsize=12)
? ? plt.yticks(fontsize=12)
? ? plt.xlabel('Area', fontdict={'fontsize': 14})
? ? plt.ylabel('Population', fontdict={'fontsize': 14})
? ? plt.title("Bubble Plot with Encircling", fontsize=14)
? ? plt.legend(fontsize=10)
? ? plt.show()
draw_scatter("F:\數(shù)據(jù)雜壇\datasets\midwest_filter.csv")

實(shí)現(xiàn)效果:

到此這篇關(guān)于python可視化分析繪制散點(diǎn)圖和邊界氣泡圖的文章就介紹到這了,更多相關(guān)python繪制內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 怎么快速自學(xué)python

    怎么快速自學(xué)python

    在本篇文章里小編給大家分享的是一篇關(guān)于怎么快速自學(xué)python的相關(guān)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)參考下。
    2020-06-06
  • Python實(shí)現(xiàn)線性插值和三次樣條插值的示例代碼

    Python實(shí)現(xiàn)線性插值和三次樣條插值的示例代碼

    這篇文章主要介紹了Python實(shí)現(xiàn)線性插值和三次樣條插值的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • Python中max函數(shù)用于二維列表的實(shí)例

    Python中max函數(shù)用于二維列表的實(shí)例

    下面小編就為大家分享一篇Python中max函數(shù)用于二維列表的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • python 列表轉(zhuǎn)為字典的兩個(gè)小方法(小結(jié))

    python 列表轉(zhuǎn)為字典的兩個(gè)小方法(小結(jié))

    這篇文章主要介紹了python 列表轉(zhuǎn)為字典的兩個(gè)小方法(小結(jié)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • python基礎(chǔ)之包的導(dǎo)入和__init__.py的介紹

    python基礎(chǔ)之包的導(dǎo)入和__init__.py的介紹

    這篇文章主要介紹了python基礎(chǔ)之包的導(dǎo)入和__init__.py的相關(guān)資料,需要的朋友可以參考下
    2018-01-01
  • Python字典的基本用法實(shí)例分析【創(chuàng)建、增加、獲取、修改、刪除】

    Python字典的基本用法實(shí)例分析【創(chuàng)建、增加、獲取、修改、刪除】

    這篇文章主要介紹了Python字典的基本用法,結(jié)合具體實(shí)例形式分析了Python字典的創(chuàng)建、增加、獲取、修改、刪除等基本操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2019-03-03
  • 講解Python中for循環(huán)下的索引變量的作用域

    講解Python中for循環(huán)下的索引變量的作用域

    這篇文章主要介紹了講解Python中for循環(huán)下的索引變量的作用域,是Python學(xué)習(xí)當(dāng)中的基礎(chǔ)知識(shí),本文給出了Python3的示例幫助讀者理解,需要的朋友可以參考下
    2015-04-04
  • Windows下Sqlmap環(huán)境安裝教程詳解

    Windows下Sqlmap環(huán)境安裝教程詳解

    這篇文章主要介紹了Windows下Sqlmap環(huán)境安裝,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Python離線安裝各種庫(kù)及pip的方法

    Python離線安裝各種庫(kù)及pip的方法

    這篇文章主要介紹了Python離線安裝各種庫(kù)及pip的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • 淺析Python字符串索引、切片、格式化

    淺析Python字符串索引、切片、格式化

    除了數(shù)字,Python中最常見(jiàn)的數(shù)據(jù)類型就是字符串,無(wú)論那種編程語(yǔ)言,字符串無(wú)處不在。本文將為大家詳細(xì)介紹Python中字符串的使用方法,需要的朋友可以參考一下
    2021-12-12

最新評(píng)論

信阳市| 锡林郭勒盟| 普洱| 巨野县| 临湘市| 三台县| 大化| 文水县| 金乡县| 兰西县| 东莞市| 益阳市| 治多县| 绥江县| 滕州市| 绥棱县| 泗水县| 刚察县| 蕲春县| 长海县| 莲花县| 景东| 泸州市| 天津市| 天等县| 广元市| 韶山市| 辉南县| 定陶县| 临江市| 虞城县| 平乡县| 铁岭市| 嘉兴市| 华容县| 铜梁县| 封丘县| 连云港市| 新竹县| 贺州市| 额济纳旗|