简体   繁体   English

如何以科学计数法导入图的数据?

[英]How do I import data in scientific notation for a plot?

So far I have been trying to import poorly formated scientific notation data into a plot using python. 到目前为止,我一直在尝试使用python将格式较差的科学计数法数据导入绘图中。 I have tried variants of 我尝试了

import matplotlib.pyplot as plt
import numpy as np

data = np.genfromtxt("/home/rex/Documents/ModLab/PhotoElec/Exp2Data.csv",delimiter=',', unpack=True, names=True)

plt.axis([-1,32, 0 , 203])

plt.title('All Aperture')
plt.xlabel('Voltage')
plt.ylabel('Current')
plt.plot(data, 'ro')

plt.show()

The data is in a csv file and looks like this but far longer. 数据在一个csv文件中,看起来像这样,但时间更长。

I2,V2,I2,V2,I2,V2
0,-0.5,0,-1,0,-0.9
2.00E-011,0.5,1.00E-010,0,3.50E-010,0.1
5.00E-011,1.5,3.00E-010,1,1.55E-009,1.1

Also when I run the assign data file I get this weird error. 另外,当我运行分配数据文件时,我得到了这个奇怪的错误。

SyntaxError: EOL while scanning string literal

Any help would be appreciated. 任何帮助,将不胜感激。

I think your problem is in the actual import - it may have been imported as a string, not a number. 我认为您的问题出在实际的导入中-它可能是作为字符串而不是数字导入的。

I'd suggest using pandas to handle the import. 我建议使用熊猫来处理进口。 If you're doing scientific computing, you'll find pandas very useful. 如果您正在进行科学计算,您会发现熊猫非常有用。 Your problem then becomes: 您的问题将变为:

import pandas
data = pandas.read_csv('Exp2Data.csv')
i2 = data.I2
v2 = data.V2
# ... plot as needed

There may also be ways for pandas to handle the plotting as well! 熊猫也可能有其他方式来处理绘图!

I think that the problem comes from your header. 我认为问题出在您的标题上。 Your header (first line) is a string and obviously, matplotlib can't plot this kind of data. 标头(第一行)是一个字符串,显然,matplotlib无法绘制此类数据。

You have to make : 您必须:

data = np.genfromtxt("/home/rex/Documents/ModLab/PhotoElec/Exp2Data.csv",
                     delimiter=',', 
                     unpack=True, 
                     names=True, 
                     skip_header = 1)
# skip_header let to go directly to your data and pass the header

I didn't run the script but it should work ;) 我没有运行脚本,但它应该可以工作;)

暂无
暂无

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

相关问题 1) 如何在 Pandas Bokeh 中切换科学记数法(使用 plot_bokeh 函数)和 2)如何将颜色居中于 0(所以白色为 0) - 1) How do I toggle scientific notation in pandas Bokeh (using the plot_bokeh function) and 2) how do I center the colours at 0 (so white is 0) 如何强制Python保持整数不受科学记数法的影响 - How do I force Python to keep an integer out of scientific notation 如何将 Integer 作为数字字符串而不是科学记数法导入 - How to Import Integer as Numeric String and not in Scientific Notation 散点的科学记数法 plot - Scientific notation for scatter plot "如何在 matplotlib 对数图上删除科学记数法" - How to remove scientific notation on a matplotlib log-log plot 当我从 Pandas 的 excel 中读取十六进制字符串时,如何抑制 python 中的科学记数法? - How do I suppress scientific notation in python when I read hexadecimal string from excel by pandas? 导出到 excel 文件时,如何抑制 Pandas DF 中的科学记数法? - How do I suppress scientific notation in pandas DF when exporting to an excel file? 如何在 Python 计算器中显示一个没有科学记数法的数字? - How Do I Display a number without it being in scientific notation in a Python calculator? 如何在 matplotlib 中使 y 轴上的数字显示以百万为单位的值而不是科学计数法? - How do I make the numbers on the y-axis show values in millions instead of in scientific notation in matplotlib? 如何强制matplotlib写出x轴标签的完整形式,避免科学记数法? - How do I force matplotlib to write out the full form of the x-axis label, avoiding scientific notation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM