Twinx() プロットへの二次軸凡例の追加
twinx() を使用して作成された 2 つの y 軸を持つプロットで、行にラベルを付けて凡例に表示するのは難しい場合があります。最初は、主軸のラベルのみが凡例に表示されます。
この問題を解決するには、次の行を使用して副軸の凡例を追加します。
ax2.legend(loc=0)
これにより、次のようになります。各軸に 1 つずつ、2 つの別個の凡例。
ただし、すべてのラベルを 1 つの凡例に表示したい場合は、次の手順に従います。手順:
-
両方の軸を定義し、線をプロットします:
ax = fig.add_subplot(111) ax2 = ax.twinx() lns1 = ax.plot(...) lns2 = ax.plot(...) lns3 = ax2.plot(...)
-
凡例のハンドルとラベルを定義します:
lns = lns1 + lns2 + lns3 labs = [l.get_label() for l in lns]
-
凡例を追加します使用:
ax.legend(lns, labs, loc=0)
この方法では、すべての軸ラベルが 1 つの凡例に表示されます。
以上がMatplotlib で `twinx()` を使用する場合、単一の凡例に両方の軸のラベルを表示するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

pythonusesahybridmodelofcompilation andtertation:1)thepythoninterpretercompilessourcodeodeplatform-indopent bytecode.2)thepythonvirtualmachine(pvm)thenexecuteTesthisbytecode、balancingeaseoputhswithporformance。

pythonisbothintersedand compiled.1)it'scompiledtobytecode forportabalityacrossplatforms.2)bytecodeisthenは解釈され、開発を許可します。

loopsareideal whenyouwhenyouknumberofiterationsinadvance、foreleloopsarebetterforsituationsは、loopsaremoreedilaConditionismetを使用します

henthenumber ofiterationsisknown advanceの場合、dopendonacondition.1)forloopsareideal foriterating over for -for -for -saredaverseversives likelistorarrays.2)whileopsaresupasiable forsaresutable forscenarioswheretheloopcontinupcontinuspificcond

pythonisnotpurelyLepted; itusesahybridapproachofbytecodecodecodecodecodecodedruntimerttation.1)pythoncompilessourcodeintobytecode、whodythepythonvirtualmachine(pvm).2)

ToconcatenateListsinpythothesheElements、使用:1)Operatortokeepduplicates、2)asettoremoveduplicates、or3)listcomplunting for controloverduplicates、各メトドハスディフェルフェルフェントパフォーマンスアンドソーダーインプリテーション。

pythonisantertedlanguage、useaseofuseandflexibility-butfactingporformantationationsincriticalapplications.1)解釈されたlikepythonexecuteline-by-lineを解釈します

Useforloopswhenthenumberofiterationsisknowninadvance、andwhiloopswheniterationsdependonacondition.1)forloopsareidealforsecenceslikelistoranges.2)


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

WebStorm Mac版
便利なJavaScript開発ツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)
