-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
35 lines (35 loc) · 1.26 KB
/
Copy pathplot.py
File metadata and controls
35 lines (35 loc) · 1.26 KB
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
import matplotlib.pyplot as p;import json
with open('plot.data')as f:d=json.load(f)
def b(d,ax):
g={};c=d.get('color','blue red orange'.split());t=d['t'];
if type(d['x'])==list:g.update(dict(zip('xyz',d['x'])))
else:
if t in['line','scatter']:g.update(d['x'])
if t=='line':
if'+'in d['x']:
t=d['x']['+'];[ax.plot(t[''],t[k],label=k)for k in t if k!=''];p.legend()
else:
ax.plot(g['x'],g['y'],color=c[0])
if'z'in g:
t=ax.twinx();t.plot(g['x'],g['z'],color=c[1]);t.tick_params(axis='y',labelcolor='red')
if'm'in g:ax.vlines(g['m'],ymin=min(g['y']),ymax=max(g['y']),color=c[2],linewidth=1)
if t=='bar':
import numpy as np;t=d['x']['+'];n=t[''];del t[''];k=list(t.keys());v=list(t.values())
x=np.arange(len(t[k[0]]));width=1/len(x)/1.2;f=len(x)/len(t)*width
[ax.bar(x+a*f,v[a],width,label=k[a])for a in range(len(t))]
ax.set_xticks(x+f);ax.set_xticklabels(n);ax.legend()
if'rc'in d:
z=d['rc'];fig,ax=p.subplots(*z)
for x in d['p']:
def ag(a,x,y):
if z[0]==1:return a[y]
if z[1]==1:return a[x]
return a[x,y]
b(x['x'],ag(ax,*x['rc']))
else:fig,ax=p.subplots();b(d,ax)
def set(x,d):
for y in[p,fig]:
if x in dir(y)and x in d:getattr(y,x)(d[x])
[set(x,d)for x in 'suptitle title xlabel'.split()]
if'out'in d:p.savefig(d['out'])
else:p.show()