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

一文詳解如何在Matplotlib中更改圖例字體大小

 更新時(shí)間:2023年05月16日 09:30:51   作者:pxr007  
在我們處理數(shù)據(jù)的時(shí)候,需要對(duì)大量的數(shù)據(jù)進(jìn)行繪圖,就免不了要使用到Matplotlib,下面這篇文章主要給大家介紹了關(guān)于如何在Matplotlib中更改圖例字體大小的相關(guān)資料,需要的朋友可以參考下

前言

使用 Matplotlib 時(shí),您可以修改繪圖的不同屬性——顏色、大小、標(biāo)簽、標(biāo)題等。

在本文中,您將了解 Matplotlib 中的圖例是什么,以及如何使用它的一些參數(shù)來(lái)使您的繪圖更具相關(guān)性。

然后,如何修復(fù) Windows Media Player 添加到媒體庫(kù)不起作用您將學(xué)習(xí)如何使用以下方法更改 Matplotlib 圖例的字體大?。?/p>

  • 這fontsize。
  • 參數(shù)prop。

什么是 Matplotlib 中的圖例?

圖例是一個(gè) Matplotlib 函數(shù),用于描述構(gòu)成圖形的元素。

考慮下圖:

import matplotlib.pyplot as plt
 
# create a plot
x = [1, 4, 6, 8]
y = [2, 5, 6, 2]
 
plt.plot(x, y)
 
plt.legend(["Data"], loc="upper right")
 
plt.show()

帶有圖例的 matplotlib 圖

在上圖中,我們使用legend. upper right“數(shù)據(jù)”的描述被分配給圖例,并使用參數(shù)值放置在圖表的右上角loc。

使用該legend功能,您可以為圖形的每一行分配不同的描述。

這是一個(gè)例子:

import matplotlib.pyplot as plt
 
age = [1, 4, 6, 8]
number = [4, 5, 6, 2, 1]
 
plt.plot(age)
plt.plot(number)
 
plt.legend(["age", "number"], loc ="upper right")
 
plt.show()

具有不同圖例描述的兩條折線圖

在上圖中,我們使用函數(shù)legend來(lái)描述圖中的每條線。

這使得查看圖表的任何人都更容易知道圖中的藍(lán)線表示age而橙色線表示。number

您可以使用以下參數(shù)值更改圖例的位置loc:

  • best
  • upper right
  • upper left
  • lower left
  • lower right
  • right
  • center left
  • center right
  • lower center
  • upper center
  • center

如何使用 Matplotlib 更改圖例字體大小fontsize參數(shù)更改 Matplotlib 中的圖例字體大小

您可以通過(guò)為參數(shù)指定字體大小值來(lái)更改 Matplotlib 圖例的字體大小fontsize。

這是默認(rèn)圖例字體大小的樣子:

import matplotlib.pyplot as plt
 
age = [1, 4, 6, 8]
number = [4, 5, 6, 2, 1]
 
plt.plot(age)
plt.plot(number)
 
plt.legend(["age", "number"], loc ="upper right")
 
plt.show()

具有默認(rèn)圖例字體大小的 matplotlib 圖

這是另一個(gè)包含參數(shù)的代碼示例fontsize:

import matplotlib.pyplot as plt
 
age = [1, 4, 6, 8]
number = [4, 5, 6, 2, 1]
 
plt.plot(age)
plt.plot(number)
 
plt.legend(["age", "number"], fontsize="20", loc ="upper left")
 
plt.show()

這是圖例的樣子:

使用 fontsize 參數(shù)的 matplotlib 圖例大小

我們?yōu)閰?shù)指定了 20 的字體大小fontsize,以獲得上圖中的圖例大小:fontsize="20"。

您還會(huì)注意到使用參數(shù)將圖例放置在圖表的左上角loc。

如何使用prop參數(shù)更改 Matplotlib 中的圖例字體大小

另一種改變圖例字體大小的方法是使用函數(shù)legend的prop參數(shù)。

下面是如何使用它:

import matplotlib.pyplot as plt
 
age = [1, 4, 6, 8]
number = [4, 5, 6, 2, 1]
 
plt.plot(age)
plt.plot(number)
 
plt.legend(["age", "number"], prop = { "size": 20 }, loc ="upper left")
 
plt.show()

使用該prop參數(shù),我們指定了 20: 的字體大小prop = { "size": 20 }。

這是輸出:

使用 prop 參數(shù)的 matplotlib 圖例大小

概括

在本文中,我們討論了legendMatplotlib 中的函數(shù)。它可用于描述構(gòu)成圖形的元素。

我們首先看到了 Matplotlib 中的圖例,以及一些示例來(lái)展示其基本用法和參數(shù)。

然后我們看到了如何使用fontsize和prop參數(shù)來(lái)更改 Matplotlib 圖例的字體大小。

總結(jié)

到此這篇關(guān)于如何在Matplotlib中更改圖例字體大小的文章就介紹到這了,更多相關(guān)Matplotlib更改圖例字體大小內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

朔州市| 五大连池市| 阜新市| 镇宁| 江山市| 河源市| 溆浦县| 波密县| 石河子市| 扶绥县| 吴堡县| 兴宁市| 巧家县| 渭南市| 宁阳县| 青田县| 墨玉县| 登封市| 莆田市| 灵璧县| 鄂伦春自治旗| 桐城市| 沭阳县| 雷波县| 阿拉善右旗| 云阳县| 莒南县| 泰顺县| 读书| 会同县| 缙云县| 荔波县| 桓台县| 滦平县| 德安县| 博客| 青神县| 新竹市| 双牌县| 昂仁县| 衢州市|