簡體   English   中英

CSV中的Python Matplotlib繪圖

[英]Python Matplotlib Plotting from csv

我可以使用matplot從像這樣的簡單csv進行繪制:

1  2
2  4
3  8
4  16
5  32
.
.

這些值由制表符分隔。 現在,我需要從csv中讀取數據,如下所示:

    #  Name Test Number1                                      \\Name of the csv
#Sometimes there is a comment which has one line
# or even more

    Category1  Number2  Test  Temperature  Voltage            \\Labels for the plot
    # [1]  [1/min]  [s]  [°C]  [mV]                           \\Units
    MinMax  2.3  5  9  48  22                                 \\Data starts here
    MinMax  9.87  6.01  8  9  3
    MinMax  1  2  3  4  5
    MinMax  99.52  5  8  6.66  0

我如何從csv和圖的標簽中獲取數據? 例如,如果要繪制測試和溫度? 有大量的行和列。

謝謝!

import csv

with open('path\to\sample.txt', 'r') as csvfile:

csvreader = csv.reader(csvfile, delimiter='\t')
foundheader=False
for row in csvreader:
    if row[0].startswith(' '):
        foundheader=True
    if foundheader:
        print row

用於測試的樣本數據

#Name Test Number1 
#Sometimes there is a comment which has one line
#or even more
# Name Test Number1 \\Name of the csv
#Sometimes there is a comment which has one line
# or even more
 Category1  Number2 Test    Temperature Voltage 
 #[1]   [1/min] [s] [°C]    [mV]    
 MinMax 2.3 5   9   48  22  
 MinMax 9.87    6.01    8   9   3
 MinMax 1   2   3   4   5
 MinMax 99.52   5   8   6.66    0

輸出

[' Category1', 'Number2', 'Test', 'Temperature', 'Voltage', '']
[' #[1]', '[1/min]', '[s]', '[\xc2\xb0C]', '[mV]', '']
[' MinMax', '2.3', '5', '9', '48', '22', '']
[' MinMax', '9.87', '6.01', '8', '9', '3']
[' MinMax', '1', '2', '3', '4', '5']
[' MinMax', '99.52', '5', '8', '6.66', '0']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM