zsh2270365028的个人博客分享 http://blog.sciencenet.cn/u/zsh2270365028

博文

[转载]The default tick formatter

已有 912 次阅读 2022-7-28 18:14 |个人分类:Python|系统分类:科研笔记|文章来源:转载

refer to: https://matplotlib.org/stable/gallery/ticks/scalarformatter.html#sphx-glr-gallery-ticks-scalarformatter-py

The example shows use of the default ScalarFormatter with different settings.

Example 1 : Default

Example 2 : With no Numerical Offset

Example 3 : With Mathtext

import matplotlib.pyplot as pltimport numpy as np

Example 1

x = np.arange(0, 1, .01)fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))fig.text(0.5, 0.975, 'Default settings',
         horizontalalignment='center',
         verticalalignment='top')ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)ax2.plot(x * 1e5, x * 1e-4)ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)ax4.plot(-x * 1e5, -x * 1e-4)fig.subplots_adjust(wspace=0.7, hspace=0.6)

scalarformatter

Example 2

x = np.arange(0, 1, .01)fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))fig.text(0.5, 0.975, 'No numerical offset',
         horizontalalignment='center',
         verticalalignment='top')ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)ax1.ticklabel_format(useOffset=False)ax2.plot(x * 1e5, x * 1e-4)ax2.ticklabel_format(useOffset=False)ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)ax3.ticklabel_format(useOffset=False)ax4.plot(-x * 1e5, -x * 1e-4)ax4.ticklabel_format(useOffset=False)fig.subplots_adjust(wspace=0.7, hspace=0.6)

scalarformatter

Example 3

x = np.arange(0, 1, .01)fig, [[ax1, ax2], [ax3, ax4]] = plt.subplots(2, 2, figsize=(6, 6))fig.text(0.5, 0.975, 'With mathtext',
         horizontalalignment='center',
         verticalalignment='top')ax1.plot(x * 1e5 + 1e10, x * 1e-10 + 1e-5)ax1.ticklabel_format(useMathText=True)ax2.plot(x * 1e5, x * 1e-4)ax2.ticklabel_format(useMathText=True)ax3.plot(-x * 1e5 - 1e10, -x * 1e-5 - 1e-10)ax3.ticklabel_format(useMathText=True)ax4.plot(-x * 1e5, -x * 1e-4)ax4.ticklabel_format(useMathText=True)fig.subplots_adjust(wspace=0.7, hspace=0.6)plt.show()

scalarformatter

Total running time of the script: ( 0 minutes 1.935 seconds)




https://m.sciencenet.cn/blog-587102-1349136.html

上一篇:[转载]设置主副刻度对象属性
下一篇:[转载]matplotlib纵坐标轴保留两位小数

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-1 03:48

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部