forked from arraystream/weplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
91 lines (65 loc) · 2.56 KB
/
plot.py
File metadata and controls
91 lines (65 loc) · 2.56 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from abc import ABC
from plotly import graph_objs as go
class AtomBuilder(ABC):
def __init__(self, data=None, layout=None):
if data is None:
data = {}
if layout is None:
layout = {}
self.data = data
self.layout = layout
class Pie(AtomBuilder):
def __init__(self, labels, values, **kwargs):
super().__init__(data=go.Pie(labels=labels, values=values, **kwargs))
class Scatter(AtomBuilder):
def __init__(self, x, y, mode='markers', **kwargs):
super().__init__(data=go.Scatter(x=x, y=y, mode=mode, **kwargs))
class Line(AtomBuilder):
def __init__(self, x, y, mode='lines', **kwargs):
super().__init__(data=go.Scatter(x=x, y=y, mode=mode, **kwargs))
class Box(AtomBuilder):
def __init__(self, y, **kwargs):
super().__init__(data=go.Box(y=y, **kwargs))
def horizontal(self):
if 'x' in self.data:
self.data.x, self.data.y = self.data.y, self.data.x
else:
self.data['x'] = self.data.y
del self.data['y']
self.data['orientation'] = 'h'
return self
class Bar(AtomBuilder):
def __init__(self, x, y, **kwargs):
super().__init__(data=go.Bar(x=x, y=y, **kwargs))
def horizontal(self):
self.data.x, self.data.y = self.data.y, self.data.x
self.data['orientation'] = 'h'
return self
class Histogram(AtomBuilder):
def __init__(self, x, **kwargs):
super().__init__(data=go.Histogram(x=x, **kwargs))
def xbins(self, start=None, end=None, size=None, bins=None):
if start is None:
start = min(self.data['x'])
if end is None:
end = max(self.data['x'])
if size is None:
if bins is None:
raise ValueError('size and bins can not be both none')
else:
size = (end - start) / bins
self.data['xbins'] = dict(start=start, end=end, size=size)
self.data['autobinx'] = False
return self
class Heatmap(AtomBuilder):
def __init__(self, z, **kwargs):
super().__init__(data=go.Heatmap(z=z, **kwargs))
class Scatter3D(AtomBuilder):
def __init__(self, x, y, z, mode='markers', **kwargs):
super().__init__(data=go.Scatter3d(x=x, y=y, z=z, mode=mode, **kwargs))
class Line3D(AtomBuilder):
def __init__(self, x, y, z, mode='lines', **kwargs):
super().__init__(data=go.Scatter3d(x=x, y=y, z=z, mode=mode, **kwargs))
class Surface(AtomBuilder):
def __init__(self, z, **kwargs):
super().__init__(data=go.Surface(z=z, **kwargs))