-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdefaultFunctions.py
47 lines (43 loc) · 1.66 KB
/
defaultFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
def section(text):
'''This is a test notebook python function'''
print("<h1>"+text+"</h1>")
def msg(msg):
return '<font class="msg dontprint">'+msg+'</font>'
def error(msg):
return '<font class="error dontprint">'+msg+'</font>'
def plot(xlines,ylines,labels=None,colors=None,styles=None,widths=None,xlabel=None,ylabel=None,caption='',name='',plotWidth=800,source=''):
global docID
if name == '':
print(msg("Please give this plot a name."))
return
try:
import matplotlib.pyplot as p
except:
print(msg("You dont have matplotlib installed. Please install it and try again."))
if type(xlines[0]) == list:
plots = len(xlines)
if labels == None:
labels = [None]*plots
if colors == None:
colors = [None]*plots
if styles == None:
styles = [None]*plots
if widths == None:
widths = [None]*plots
for xline,yline,label,color,style,width in zip(xlines,ylines,labels,colors,styles,widths):
p.plot(xline,yline,label=label,linewidth=width,color=color,linestyle=style)
if any(labels):
p.legend(loc='best')
p.grid()
path = 'Archieves/'+docID+'/Images/'+name+'.png'
try:
os.mkdir(os.getcwd()+'/Archieves/'+docID)
except FileExistsError:
pass
try:
os.mkdir(os.getcwd()+'/Archieves/'+docID+'/Images')
except FileExistsError:
pass
p.savefig(path)
print('<br><center><figcaption>'+caption+'</figcaption>'+'<img style="width:'+str(plotWidth)+'" src="'+path+'"><br>Source: '+source+'</center><br>')