我正在尝试从.txt文件进行绘制,并且执行图例时出现错误。我不确定这里的错误是什么。这是代码:
myForm:FormGroup
myFormArray:FormArray;
values=[
{LanguageName: 'English', ID : 2},
{LanguageName: 'Dutch', ID : 1},
{LanguageName: 'portuguese', ID: 3},
]
ngOnInit() {
this.myForm=this.fb.group({
data:this.fb.array(this.createFormArray(this.values))
})
this.myFormArray=this.fb.array(this.createFormArray(this.values));
}
createFormArray(values:any):FormGroup[]
{
return values.map(x=>{
return this.fb.group(
{
LanguageName:x.LanguageName,
ID:x.ID
}
)
})
}
这是输出:
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
plt.close('all')
#-----------------------------------------------------------------------
# read data
#-----------------------------------------------------------------------
DATA_PATH = '/home/public/WS1819_Ex3/experiments/exercise_02/Absorption.txt'
data = np.genfromtxt(DATA_PATH, skip_header=1)
x, y1, y2, y3 = data[:,0], data[:,1], data[:,2], data[:,3]
#-----------------------------------------------------------------------
# prepare canvas
#-----------------------------------------------------------------------
fig, ax = plt.subplots(1, 1)
ax.grid(True)
ax.set_xlabel('Abstand [cm]')
ax.set_ylabel(u'Intensität [V]')
ax.set_title(u'Absorption von Licht in Wasser')
# set logarithmic y-scale
ax.set_yscale('log')
#-----------------------------------------------------------------------
# plot data
plt.plot(x,y1)
plt.show()
ax.legend()
fig.savefig('Absorption.pdf')
答案 0 :(得分:-1)
尝试一下。
# plot data
p1 = plt.plot(x,y1)
plt.legend((p1[0]), (header[0]), fontsize=12, ncol=1, framealpha=0, fancybox=True)