简体   繁体   English

有没有办法将科学记数法转换为 Python 中的前几个小数位?

[英]Is there a way to convert scientific notation to just the first few decimal places in Python?

I have a list of 1111 values in scientific notation.我有一个用科学记数法表示的 1111 个值的列表。 Here are a few examples:这里有一些例子:

6.042968853864891e-12, 6.042894605467602e-12, 6.042777396826408e-12, 6.042616263531836e-12, 6.042410211830538e-12, 6.042158216350682e-12, 

Is there a way I can convert this to just a list of 6.0429885, 6.04289460, 6.04277739, 6.04261626, 6.04241021, 6.04215821 (8 decimal places)?有没有办法可以将其转换为仅包含 6.0429885、6.04289460、6.04277739、6.04261626、6.04241021、6.04215821(8 个小数位)的列表? I don't want the scientific notation part (e-12).我不想要科学记数法部分 (e-12)。

I am ultimately trying to plot longitude on the x axis, latitude on the y-axis and have the points different sizes or colors based on density values (the density values are the numbers above in scientific notation).我最终试图在 x 轴上绘制经度,在 y 轴上绘制纬度,并根据密度值(密度值是上面的科学计数法中的数字)使点具有不同的大小或颜色。 Here is a plot I have of just the longitude and latitude.这是我只有经度和纬度的情节。 I want to have this and each point be varying size depending on what the density is at that location.我想要这个,每个点的大小取决于该位置的密度。

在此处输入图片说明

Seems like you just need to multipy these numbers by 1e12 then round to 8 decimal places, right?似乎您只需要将这些数字乘以 1e12 然后四舍五入到小数点后 8 位,对吗?

a = [6.042968853864891e-12, 6.042894605467602e-12, 6.042777396826408e-12, 6.042616263531836e-12, 6.042410211830538e-12, 6.042158216350682e-12, 
]

b = [round(i*1e12,8) for i in a]

# if you want to scale your plot, then you shouldn't need to change the list itself, rather do this to your plot:

# if you have an ax, do:
ax.set_ylim([0,1e-11]) 
# this will give you a fixed y axis limit between 0 and 1e-11.


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM