在利用python的matplotlib包进行数据可视化时经常会需要使用科学计数法,今天分享一下标签设置科学计数法的方法。共设置三个ax进行对比。
不多说了,详见代码。
```python
# -*- encoding: utf-8 -*-
'''
@File : demo1.py
@Time : 2022/01/25 23:14:35
@Author : HMX
@Version : 1.0
@Contact : kzdhb8023@163
演示科学计数法
'''# here put the import lib
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import ticker
import numpy as npsize1 = 10.5
Params.update(
{
'text.usetex': False,
'font.family': 'stixgeneral',
'mathtext.fontset': 'stix',
"font.family":'serif',
"font.size": size1,
"font.serif": ['Times New Roman'],
}
)
fontdict = {'weight': 'bold','size':size1,'family':'SimSun'}
fig,[ax1,ax2,ax3] = plt.subplots(1,3,figsize = (6,2))
for ax in [ax1,ax2,ax3]:ax.tick_params(axis='both',which='both',direction='out')ax.set_xticks(np.arange(-5,6,2))ax.set_ylim(-5000,5000)ax.set_xlim(-5,5)ax.plot(np.arange(-5,6),np.arange(-5,6)*1000)ax1.set_title('实验组',fontdict = fontdict)
ax2.set_title('对照组',fontdict = fontdict)
ax3.set_title('空白组',fontdict = fontdict)# 实验组
formatter = ticker.ScalarFormatter(useMathText=True)
formatter.set_scientific(True)
formatter.set_powerlimits((0,0))
ax1.yaxis.set_major_formatter(formatter)
# 对照组
ax2.ticklabel_format(style='sci', scilimits=(0,0), axis='y')
# 空白组plt.tight_layout()
plt.savefig('demo1.png',dpi = 600)
plt.show()
通常情况下我们需要的是ax1中的样式而非第二个ax2。
今天的分享就到这里了,欢迎大家关注我的公众号【森气笔记】
本文发布于:2024-01-28 10:28:39,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17064089236771.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |