여러 Matplotlib 하위 플롯에 대한 단일 범례 생성
Matplotlib를 사용하여 여러 하위 플롯에 걸쳐 유사한 정보를 플롯할 때 단일 범례를 생성하는 것이 도움이 될 수 있습니다. 모든 서브플롯에 적용되는 범례입니다. 이는 각 서브플롯의 선에 대한 일관된 참조를 제공하여 데이터 해석을 단순화합니다.
이를 달성하려면 마지막 축에서 get_legend_handles_labels() 함수를 활용하거나 plt.gca().get_legend_handles_labels( ) pyplot 인터페이스를 사용하는 경우. 이 함수는 label= 인수에서 필요한 범례 핸들과 레이블을 수집합니다.
단일 범례를 생성하려면 fig.legend(handles, labels, loc='upper center')를 호출합니다. 여기서 fig는 다음을 포함하는 그림입니다. 서브플롯과 loc는 범례의 위치를 지정합니다.
예를 들어, 동일한 선이 있는 3x3 서브플롯 그리드가 있는 경우 다음 코드는 모든 서브플롯 위에 단일 범례를 추가합니다.
import matplotlib.pyplot as plt import numpy as np # Generate data for the subplots data = np.random.rand(9) # Create the subplots fig, axes = plt.subplots(3, 3) # Plot the data on each subplot for ax, datum in zip(axes.flatten(), data): ax.plot(datum) # Get the legend handles and labels handles, labels = plt.gca().get_legend_handles_labels() # Create the single legend plt.legend(handles, labels, loc='upper center') plt.show()
위 내용은 여러 Matplotlib 하위 플롯에 대한 단일 범례를 만드는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

forhandlinglargedatasetsinpython, usenumpyarraysforbetterperformance.1) numpyarraysarememory-effic andfasterfornumericaloperations.2) leveragevectorization foredtimecomplexity.4) managemoryusage withorfications data

inpython, listsusedyammoryAllocation과 함께 할당하고, whilempyarraysallocatefixedMemory.1) listsAllocatemememorythanneedInitiality.

Inpython, youcansspecthedatatypeyfelemeremodelerernspant.1) usenpynernrump.1) usenpynerp.dloatp.ploatm64, 포모 선례 전분자.

numpyissentialfornumericalcomputinginpythonduetoitsspeed, memory-efficiency 및 comperniveMathematicaticaltions

contiguousUousUousUlorAllocationScrucialForraysbecauseItAllowsOfficationAndFastElementAccess.1) ItenableSconstantTimeAccess, o (1), DuetodirectAddressCalculation.2) Itimprovesceeffiency theMultipleementFetchespercacheline.3) Itsimplififiesmomorym

slicepaythonlistisdoneusingthesyntaxlist [start : step : step] .here'showitworks : 1) startistheindexofthefirstelementtoinclude.2) stopistheindexofthefirstelemement.3) stepisincrementbetwetweentractionsoftortionsoflists

NumpyAllowsForVariousOperationsOnArrays : 1) BasicArithmeticLikeadDition, Subtraction, A 및 Division; 2) AdvancedOperationsSuchasmatrixmultiplication; 3) extrayintondsfordatamanipulation; 5) Ag

Arraysinpython, 특히 Stroughnumpyandpandas, areestentialfordataanalysis, setingspeedandefficiency


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경