hack ¤Î¤¿¤á¤Î¥Í¥¿Ä¢, etc,,,

¾õ¶·

Google Colabolatory ¤Î matplotlib ¤Ç»¶ÉÛ¿Þ(scatter)¤òÉÁ¤¤¤¿¤é¡¢6·å¤Ë¼ý¤Þ¤ë¾ì¹ç¤Ï¤½¤Î¤Þ¤Þɽ¼¨¤µ¤ì¤ë¤Î¤À¤¬¡¢6·å¤òĶ¤¨¤ë¤È
 |
-+---+---+---+---+---+---+-
0.0 0.2 0.4 0.6 0.8 1.0 1.2
                          1e6
¤ß¤¿¤¤¤Êɽ¼¨¤Ë¤Ê¤ë¡£

½ñ¼°¤ÎÊѹ¹ÊýË¡¤ò¡Ömatplotlib numeric format axis¡×¥°¥°¤Ã¤Æ¤ß¤¿¤é ¤Ç
plt.gca().xaxis.set_major_formatter(plt.matplotlib.ticker.StrMethodFormatter('{x:e}'))
# 0.0e6 0.2e6 ... 1.2e6 ¤Î¤è¤¦¤Ë¤Ê¤ë
plt.gca().xaxis.set_major_formatter(plt.matplotlib.ticker.StrMethodFormatter('{x:,.0f}'))
# 0 200,000 ... 1,200,000 ¤Î¤è¤¦¤Ë¤Ê¤ë
¤ß¤¿¤¤¤Ê½ñ¤­Êý¤¬½ÐÍè¤ë¤³¤È¤ò¸«¤Ä¤±¤¿¤¬¡¢¹ï¤ß¤Î¿ôÃͤËÊÒ¤Ãü¤«¤é e6 ¤¬ÉÕ¤¯¤Î¤ÏÈѤ¤¤Î¤Ç¡¢default ¤Î¤è¤¦¤Ëü¤Ã¤³¤ËÇÜΨ¤òź¤¨¤Æ¤Û¤·¤¤¤È¤³¤í¡£
º£²ó¤Î¾ì¹ç¡¢¼´¤¬¶â³Û¤äµ÷Î¥¤Ê¤Î¤ÇÇÜΨ¤Ï 10,000 ¤À¤ÈÍ­¤êÆñ¤¤¡£

²òË¡

¡Ömatplotlib axis 1e6¡×¤Ç¥°¥°¤Ã¤¿¤é¡¢
·Ðͳ¤Ç ¤Ë¤¿¤É¤êÃ夤¤¿¡£

default ¤Î legend ¤Ï
legend = plt.legend()
print(legend)
¤È¤«¤¹¤ë¤È ScalarFormatter ¤Ç¤¢¤ë¤³¤È¤¬¤ï¤«¤Ã¤¿¡£

source į¤á¤Æ¤ß¤¿¤È¤³¤í¡¢°Ê²¼¤Î¤è¤¦¤Ê undocumented ¤ÊÆ°ºî¤òȯ¸«¡£
  • .set_powerlimits*1 ¤Ç n==m ¤Ë¤Ê¤Ã¤Æ¤ëÇÜΨɽ¼¨¤¬¶¯À©¤µ¤ì¤ë¡£
  • _usetex ¤ä useMathText ¤¬ True ¤Ë¤Ê¤Ã¤Æ¤ë 1eN ¤Ç¤Ï¤Ê¤¯ 10^N ɽ¼¨¤Ë¤Ê¤ë¡£
    • _usetex¡¡¤ÏÆâÉôÊÑ¿ô¤Ã¤Ý¤¤¤Î¤Ç¡¢.set_useMathText(val) ¤ÇÀßÄꤹ¤ë¤Î¤¬Îɤ¤¡©
¤³¤ì¤é¤Î¥Ç¥Õ¥©¥ë¥ÈÃͤϰʲ¼¤Î rcParams ¤«¤é°ú¤¤¤Æ¤¤¤ë¤Î¤Ç¡¢¤³¤Á¤é¤òÊѤ¨¤ë¤È¤¤¤¦¤Î¤â¼ê¤«¡©
  • rcParams['axes.formatter.limits']
  • rcParams['text.usetex']
  • rcParams['axes.formatter.use_mathtext']
text.usetex ¤Ï TeX ¤Î»ÈÍѤΠON/OFF ¤«¤Ê¡©

plt ¸Æ¤ÖÁ°¤Ë
plt.rcParams['axes.formatter.use_mathtext'] = True
plt.rcParams['axes.formatter.limits'] = (4,4)
¤Î¤è¤¦¤Ë¥Ç¥Õ¥©¥ë¥ÈÊѹ¹¤·¤Æ¤ª¤¯¤«¡¢
formatter = plt.matplotlib.ticker.ScalarFormatter() # It's default formatter, but I need some customize.
formatter.set_powerlimits((4, 4)) # Force format by power with 1e4
formatter.set_useMathText(True) # Show the multiplyer as x10^N instead of 1eN 
plt.gca().xaxis.set_major_formatter(formatter)
plt.gca().yaxis.set_major_formatter(formatter)
¤ß¤¿¤¤¤Ë¤·¤ÆÄ´À°¤·¤Æ¤âÎɤ¤¤è¤¦¤À¡£

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

WikiÆ⸡º÷

¥Õ¥ê¡¼¥¨¥ê¥¢

´ÉÍý¿Í/Éû´ÉÍý¿Í¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹