[英]How to change scientific notation form in Matplotlib
This is my code.这是我的代码。
time = sig[:, 0] # data first column: time
displacement = sig[:, 1] # data second column: displacement
font = {'family': 'Times New Roman', 'weight': 'bold', 'size': 16}
fig, ax = plt.subplots(figsize = (9, 8)) # set figure size (width,height)
ax.plot(time, displacement, linewidth = 2)
ax.set_xlim(0, 3e-3) # set x-axis limit
ax.set_ylim(-4e-6, 1e-6) # set y-axis limit
ax.set_xticklabels([0, 0.5, 1, 1.5, 2, 2.5, 3])
ax.tick_params(labelsize = 16) # tick_params can only change label size
labels = ax.get_xticklabels() + ax.get_yticklabels()
for label in labels: # thus use for loop(?) change font name and weight
label.set_fontname('Times New Roman')
label.set_fontweight('bold')
ax.set_xlabel('Time (msec.)', font)
ax.set_ylabel('Displacement (m)', font)
plt.show()
And this is the code's result.这是代码的结果。
But actually, that's what I want to get.但实际上,这正是我想要得到的。
How can I change the notation form from 1e-6
to 10^-6
and also make the font bold.如何将符号形式从
1e-6
更改为10^-6
并使字体加粗。
To change the scientific notation of ticklabel:要更改刻度标签的科学记数法:
ax.ticklabel_format(useMathText=True)
To change the text properties, grab the text object with:要更改文本属性,请使用以下命令获取文本 object:
ty = ax.yaxis.get_offset_text()
ty.set_fontweight('bold')
ty.set_size(16)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.