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

Matplotlib多子圖使用一個(gè)圖例的實(shí)現(xiàn)

 更新時(shí)間:2023年08月16日 10:04:05   作者:Threetiff  
多子圖是Matplotlib中的一個(gè)功能,可以在同一圖形中創(chuàng)建多個(gè)子圖,本文主要介紹了Matplotlib多子圖使用一個(gè)圖例的實(shí)現(xiàn),感興趣的可以了解一下

1 所有子圖的圖例相同

利用函數(shù) fig.axe.get_legend_handles_labels() 得到圖的 line label

import matplotlib.pyplot as plt
fig = plt.figure()
axes = fig.subplots(nrows=2, ncols=2)
for ax in fig.axes:
    ax.plot([0, 10], [0, 10], label='linear')
# 使用最后一個(gè)子圖的圖例
lines, labels = fig.axes[-1].get_legend_handles_labels()
fig.legend(lines, labels, loc = 'upper center') # 圖例的位置,bbox_to_anchor=(0.5, 0.92),
plt.show()

2 所有的子圖圖例不同

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 501)
fig = plt.figure()
axes = fig.subplots(nrows=2, ncols=2)
axes[0, 0].plot(x,np.sin(x),color = 'k',label="sin(x)")
axes[0, 1].plot(x,np.cos(x),color = 'b',label="cos(x)")
axes[1, 0].plot(x,np.sin(x) + np.cos(x),color = 'r',label="sin(x)+cos(x)")
axes[1, 1].plot(x,np.sin(x) - np.cos(x),color = 'm',label="sin(x)-cos(x)")
lines = []
labels = []
# 利用循環(huán)得到每一個(gè)子圖的圖例
for ax in fig.axes:
    axLine, axLabel = ax.get_legend_handles_labels()
    lines.extend(axLine)
    labels.extend(axLabel)
fig.legend(lines, labels, loc = 'upper right')  # 圖例的位置,bbox_to_anchor=(0.5, 0.92),
plt.show()

參考鏈接

Matplotlib 多個(gè)子圖使用一個(gè)圖例

到此這篇關(guān)于Matplotlib多子圖使用一個(gè)圖例的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Matplotlib多子圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

鄱阳县| 商都县| 洮南市| 仪陇县| 大厂| 东辽县| 木兰县| 嘉定区| 嘉定区| 泰和县| 延长县| 宝鸡市| 海口市| 嵊泗县| 屯昌县| 麻栗坡县| 永顺县| 德清县| 西吉县| 化德县| 灯塔市| 南城县| 沙洋县| 麻城市| 永康市| 富裕县| 宝兴县| 西和县| 陕西省| 七台河市| 自贡市| 邓州市| 微山县| 龙海市| 扎兰屯市| 云梦县| 邢台市| 惠来县| 于都县| 武平县| 兴海县|