matplotlib では、浮動小数点値の目盛ラベルの形式を指定して、特定の小数点以下の桁を表示したり、科学的表示を抑制したりできます。 notation.
これを実現するには、matplotlib.ticker モジュールの FormatStrFormatter クラスを使用できます。このフォーマッタを使用すると、ラベルの書式文字列を指定できます。
たとえば、Y 軸に小数点以下 2 桁を表示するには、次のコードを使用できます。
<code class="python">import matplotlib.pyplot as plt from matplotlib.ticker import FormatStrFormatter fig, ax = plt.subplots() ax.yaxis.set_major_formatter(FormatStrFormatter('%.2f'))</code>
To科学的表記法を抑制するには、
<code class="python">ax.yaxis.set_major_formatter(FormatStrFormatter('%f'))</code>
のような書式指定文字列を使用します。これらのフォーマッタをコードに適用すると、サブプロットの y 軸で目的の書式設定を実現できます:
<code class="python"># ... (same code as in the original snippet) ... axarr[0].yaxis.set_major_formatter(FormatStrFormatter('%.2f')) axarr[1].yaxis.set_major_formatter(FormatStrFormatter('%.2f')) axarr[2].yaxis.set_major_formatter(FormatStrFormatter('%.2f'))</code>
FormatStrFormatter を使用すると、特定の視覚化ニーズに合わせて目盛りラベルの書式設定を正確に制御できます。
以上がMatplotlib で浮動小数点値の目盛ラベルの形式を指定するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。