我需要可视化一些数据.它是基本的2D网格,其中每个单元格都有浮点值.我知道如何在OpenCV中为颜色分配颜色和绘制网格.但这里的重点是,有太多的价值观,所以几乎不可能做到这一点.我正在寻找一些方法,我可以使用渐变.例如,值-5.0将由蓝色,0 - 黑色和+5.0表示为红色.在Python中有没有办法做到这一点?
这是我正在谈论的示例数据
A B C D
A -1.045 2.0 3.5 -4.890
B -5.678 3.2 2.89 5.78
Run Code Online (Sandbox Code Playgroud) 我有这个错误:
File "zzz.py", line 70
else:
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
导致问题的行在代码中标有注释:
def FileParse(self, table_file):
vars={}
tf = open(table_file, 'r')
for line in tf:
if line.startswith("#") or line.strip() == "": pass
elif line.startswith("n_states:"):
self.n_states = str(line[9:].strip())
elif line.startswith("neighborhood:"):
self.neighborhood = str(line[13:].strip())
elif line.startswith("symmetries:"):
self.symmetries = str(line[11:].strip())
elif line.startswith("var "):
line = line[4:]
ent = line.replace('=',' ').\
replace('{',' ').\
replace(',',' ').\
replace(':',' ').\
replace('}',' ').\
replace('\n','').split()
vars[ent[0]] = []
for e in ent[1:]:
if e in vars: vars[ent[0]] += vars[e]
else:
vars[ent[0].append(int(e))] …Run Code Online (Sandbox Code Playgroud) 我有一个应该从文件中逐行读取的函数,当一行不以'>'或''开头时,读取停止.它应该将行存储在vector中并返回它.
这是代码:
#include <cstdlib>
#include <iostream>
#include <string>
#include <stdio.h>
#include <fstream>
#include <vector>
using namespace std;
string getseq(char * db_file) // gets sequences from file
{
string seqdb;
vector<string> seqs;
ifstream ifs(db_file);
string line;
//vector<char> seqs[size/3];
while(ifs.good())
{
getline(ifs, seqdb);
if (seqdb[0] != '>' & seqdb[0]!=' ')
{
seqs.push_back(seqdb);
}
}
ifs.close();
//return seqs;
//return seqs;
}
int main(int argc, char * argv[1])
{
cout << "Sequences: \n" << getseq(argv[1]) << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译器(g ++)返回:
fasta_parser.cpp: In …Run Code Online (Sandbox Code Playgroud) python ×2
c++ ×1
colors ×1
gradient ×1
grid ×1
if-statement ×1
indentation ×1
return ×1
return-value ×1
syntax-error ×1
vector ×1