欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python?matplotlib各種畫圖

 更新時(shí)間:2021年12月26日 10:16:13   作者:L-M-Y  
這篇文章主要介紹了python?matplotlib各種畫圖,matplotlib是一種優(yōu)秀的python數(shù)據(jù)可視化第三方庫(kù),使用matpltlib庫(kù)畫圖時(shí),先將它引入,加載里面的pyplot,并命名為plt,然后使用plot函數(shù)畫圖<BR>,下面一起來(lái)了解更詳細(xì)內(nèi)容吧

1.引入matpltlib庫(kù)

matplotlib是一種優(yōu)秀的python數(shù)據(jù)可視化第三方庫(kù)
使用matpltlib庫(kù)畫圖時(shí),先將它引入,加載里面的pyplot,并命名為plt,然后使用plot函數(shù)畫圖

import matplotlib.pyplot as plt #plt是引入模塊的別名


2.pyplot基礎(chǔ)圖標(biāo)函數(shù)總結(jié)

3.plot函數(shù)畫圖語(yǔ)法規(guī)則

plot函數(shù)參數(shù):plot([x],y,[format],**kwargs)

各類語(yǔ)法太多啦,偷幾張MOOC的圖放上來(lái)~

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

4.折線圖

from matplotlib import pyplot as plt

#生成數(shù)據(jù)
#橫坐標(biāo)數(shù)據(jù)從2017到2022,第三個(gè)參數(shù)可控制步長(zhǎng),可寫可不寫
x = range(2017, 2022)
#y對(duì)應(yīng)縱坐標(biāo)的值
y1 = [49, 48, 45, 52, 50]
y2 = [60, 62, 61, 65, 63]
#生成圖形
plt.title("LMY and her mother's weight")
plt.xlabel('year')
plt.ylabel('kg')
plt.plot(x, y1, color='green', label='LMY')
plt.plot(x, y2, color='purple', label='mother')
plt.grid(alpha=0.5)
plt.legend(loc='upper right')
#顯示圖形
plt.show()

請(qǐng)?zhí)砑訄D片描述

4.散點(diǎn)圖

from matplotlib import pyplot as plt
import numpy as np

# 生成數(shù)據(jù)
# 橫坐標(biāo)數(shù)據(jù)從2017到2022,第三個(gè)參數(shù)可控制步長(zhǎng),可寫可不寫
x = range(2017, 2022)
# y對(duì)應(yīng)縱坐標(biāo)的值
y1 = [49, 48, 45, 52, 50]
y2 = [60, 62, 61, 65, 63]
# 生成圖形
plt.title("LMY and her mother's weight")
plt.xlabel('year')
plt.ylabel('kg')
# 點(diǎn)的大小
area = np.pi*4**2
plt.scatter(x, y1, s=area, c='yellow', alpha=1)
plt.scatter(x, y2, s=area, c='blue', alpha=1)
plt.legend()
plt.yticks(())
plt.show()

請(qǐng)?zhí)砑訄D片描述

5.直方圖

from matplotlib import pyplot as plt
import numpy as np

# 生成數(shù)據(jù)
# 橫坐標(biāo)數(shù)據(jù)從2017到2022,第三個(gè)參數(shù)可控制步長(zhǎng),可寫可不寫
x = [2017, 2018, 2019, 2020, 2021]
# y對(duì)應(yīng)縱坐標(biāo)的值
y1 = [49, 48, 45, 52, 50]
y2 = [60, 62, 61, 65, 63]
# 生成圖形
plt.title("LMY and her mother's weight")
plt.ylabel('frequency')
plt.xlabel('kg')
# 點(diǎn)的大小
plt.hist(y1, bottom=None, color='purple')
plt.hist(y2, bottom=None, color='pink')
plt.show()

# n, bins, patches = plt.hist(arr, bins=50, normed=1, facecolor='green', alpha=0.75)
'''
arr:需要計(jì)算直方圖的一維數(shù)組
bins:直方圖的柱數(shù),可選項(xiàng),默認(rèn)為10
normed:是否將得到的直方圖向量歸一化,默認(rèn)為0
facecolor:直方圖顏色
alpha:透明度
'''

在這里插入圖片描述

6.條形圖

縱向

from matplotlib import pyplot as plt
import numpy as np

arr = np.arange(2017, 2022)
x = [49, 48, 45, 52, 50]  # x軸
y = [2017, 2018, 2019, 2020, 2021]
rect = plt.bar(arr, x, width=0.5)
plt.title('LMY')
plt.xlabel('weight')
plt.ylabel('year')
plt.legend()

plt.show()

請(qǐng)?zhí)砑訄D片描述

橫向

請(qǐng)?zhí)砑訄D片描述

多條

from matplotlib import pyplot as plt
import numpy as np

arr = np.arange(2017, 2022)
x1 = [49, 48, 45, 52, 50]  # x軸
x2 = [60, 62, 61, 65, 63]
y = [2017, 2018, 2019, 2020, 2021]
rects1 = plt.bar(arr, x1, 0.5, color='purple', label='LMY')
rects2 = plt.bar(arr, x2, 0.5, color='yellow', label='Mother', alpha=0.3)
plt.title("LMY and her mother's weight")
plt.xlabel('weight')
plt.ylabel('year')
plt.legend()

plt.show()

請(qǐng)?zhí)砑訄D片描述

7.餅圖

from matplotlib import patches, pyplot as plt
import numpy as np

label_list = ['49', '48', '45', '52', '50']
size = [20, 20, 20, 20, 20]
# 各部分的顏色
color = ['red', 'pink', 'blue', 'green', 'purple']
explode = [0, 0, 0.15, 0, 0]

patches, l_text, p_text = plt.pie(size, explode=explode, colors=color, labels=label_list,
                                  labeldistance=1.2, autopct="%1.2f%%", shadow=False, startangle=90, pctdistance=0.6)
plt.axis('equal')
plt.title("LMY's weight")
plt.legend(loc='upper left')
plt.show()

請(qǐng)?zhí)砑訄D片描述

到此這篇關(guān)于python matplotlib各種畫圖的文章就介紹到這了,更多相關(guān)python matplotlib畫圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 在Windows系統(tǒng)上搭建Nginx+Python+MySQL環(huán)境的教程

    在Windows系統(tǒng)上搭建Nginx+Python+MySQL環(huán)境的教程

    這篇文章主要介紹了在Windows系統(tǒng)上搭建Nginx+Python+MySQL環(huán)境的教程,文中使用flup中間件及FastCGI方式連接,需要的朋友可以參考下
    2015-12-12
  • Python+tkinter實(shí)現(xiàn)音樂(lè)下載軟件的制作

    Python+tkinter實(shí)現(xiàn)音樂(lè)下載軟件的制作

    平常我們下載的歌曲,都是各種妖魔鬼怪的格式橫行,想下載下來(lái)用一下都不行,還只能在它的播放器內(nèi)聽(tīng),這誰(shuí)受得了~本文就來(lái)用Python制作個(gè)音樂(lè)下載軟件,需要的可以參考一下
    2022-09-09
  • 獲取python運(yùn)行輸出的數(shù)據(jù)并解析存為dataFrame實(shí)例

    獲取python運(yùn)行輸出的數(shù)據(jù)并解析存為dataFrame實(shí)例

    這篇文章主要介紹了獲取python運(yùn)行輸出的數(shù)據(jù)并解析存為dataFrame實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07
  • Python自動(dòng)化測(cè)試框架pytest的詳解安裝與運(yùn)行

    Python自動(dòng)化測(cè)試框架pytest的詳解安裝與運(yùn)行

    這篇文章主要為大家介紹了Python自動(dòng)化測(cè)試框架pytest的簡(jiǎn)介以及安裝與運(yùn)行,有需要的朋友可以借鑒參考下希望能夠有所幫助,祝大家多多進(jìn)步
    2021-10-10
  • Python+Selenium定位不到元素常見(jiàn)原因及解決辦法(報(bào):NoSuchElementException)

    Python+Selenium定位不到元素常見(jiàn)原因及解決辦法(報(bào):NoSuchElementException)

    這篇文章主要介紹了Python+Selenium定位不到元素常見(jiàn)原因及解決辦法(報(bào):NoSuchElementException),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-03-03
  • 公眾號(hào)接入chatGPT的詳細(xì)教程 附Python源碼

    公眾號(hào)接入chatGPT的詳細(xì)教程 附Python源碼

    這篇文章主要介紹了公眾號(hào)接入chatGPT教程附Python源碼,這里需要大家準(zhǔn)備一個(gè)域名,一臺(tái)服務(wù)器和一個(gè)公眾號(hào),本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-02-02
  • 一文教會(huì)你使用Python來(lái)下一場(chǎng)雪

    一文教會(huì)你使用Python來(lái)下一場(chǎng)雪

    這篇文章主要給大家介紹了關(guān)于使用Python來(lái)下一場(chǎng)雪的相關(guān)資料,文章描述了大雪緩緩下落的場(chǎng)景,并提供了完整的代碼示例,對(duì)大家學(xué)習(xí)或者使用python具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2024-11-11
  • 基于Python數(shù)據(jù)結(jié)構(gòu)之遞歸與回溯搜索

    基于Python數(shù)據(jù)結(jié)構(gòu)之遞歸與回溯搜索

    今天小編就為大家分享一篇基于Python數(shù)據(jù)結(jié)構(gòu)之遞歸與回溯搜索,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-02-02
  • Python yield 使用方法淺析

    Python yield 使用方法淺析

    本篇文章主要介紹了Python yield 使用方法淺析,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-05-05
  • Pytorch中.detach()與.data的用法小結(jié)

    Pytorch中.detach()與.data的用法小結(jié)

    這篇文章主要介紹了Pytorch中.detach()與.data的用法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-07-07

最新評(píng)論