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

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

 更新時間:2023年08月16日 10:04:05   作者:Threetiff  
多子圖是Matplotlib中的一個功能,可以在同一圖形中創(chuàng)建多個子圖,本文主要介紹了Matplotlib多子圖使用一個圖例的實現(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')
# 使用最后一個子圖的圖例
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)得到每一個子圖的圖例
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 多個子圖使用一個圖例

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

相關文章

最新評論

卓尼县| 祁阳县| 纳雍县| 镶黄旗| 岗巴县| 杭锦后旗| 上栗县| 明光市| 成武县| 从江县| 丰台区| 锡林浩特市| 红河县| 景宁| 湖口县| 武城县| 永兴县| 阳谷县| 浦东新区| 绥棱县| 页游| 安达市| 板桥市| 宣化县| 临夏县| 永寿县| 林州市| 北宁市| 张家川| 胶州市| 北辰区| 大足县| 介休市| 济南市| 盐源县| 临颍县| 丹凤县| 望城县| 溧水县| 沂源县| 仁化县|