This repository was archived by the owner on Mar 22, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 562
Expand file tree
/
Copy pathchart_components.py
More file actions
194 lines (161 loc) · 4.53 KB
/
Copy pathchart_components.py
File metadata and controls
194 lines (161 loc) · 4.53 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from copy import deepcopy
from .ggplot import ggplot
class ggtitle(object):
"""
Add a title to your plot
Parameters
----------
title:
Your plot title
Examples
--------
>>> ggplot(mpg, aes(x='hwy')) + geom_hisotgram() + ggtitle("MPG Plot")
"""
def __init__(self, title):
if title is None:
raise Exception("No title specified!")
self.title = title
def __radd__(self, gg):
if isinstance(gg, ggplot):
gg = deepcopy(gg)
gg.title = self.title
return gg
else:
return self
class xlim(object):
"""
Set upper and lower limits for your x axis
Parameters
----------
lower_limit:
lower limit for axis
upper_limit:
upper limit for axis
Examples
--------
>>> ggplot(mpg, aes(x='hwy')) + geom_hisotgram() + xlim(0, 20)
"""
def __init__(self, low = None, high = None):
if low is not None:
try:
_ = low - 0
except TypeError:
raise Exception("The 'low' argument to", self.__class__.__name__,
"must be of a numeric type or None")
if high is not None:
try:
_ = high - 0
except TypeError:
raise Exception("The 'high' argument to", self.__class__.__name__,
"must be of a numeric type or None")
self.low, self.high = low, high
def __radd__(self, gg):
gg = deepcopy(gg)
gg.xlimits = [self.low, self.high]
return gg
class ylim(object):
"""
Set upper and lower limits for your y axis
Parameters
----------
lower_limit:
lower limit for axis
upper_limit:
upper limit for axis
Examples
--------
>>> ggplot(mpg, aes(x='hwy')) + geom_hisotgram() + ylim(0, 5)
"""
def __init__(self, low = None, high = None):
if low is not None:
try:
_ = low - 0
except TypeError:
raise Exception("The 'low' argument to", self.__class__.__name__,
"must be of a numeric type or None")
if high is not None:
try:
_ = high - 0
except TypeError:
raise Exception("The 'high' argument to", self.__class__.__name__,
"must be of a numeric type or None")
self.low, self.high = low, high
def __radd__(self, gg):
gg = deepcopy(gg)
gg.ylimits = [self.low, self.high]
return gg
class xlab(object):
"""
Set label for x axis
Parameters
----------
label:
label for your axis
Examples
--------
>>> ggplot(mpg, aes(x='hwy')) + geom_hisotgram() + xlab("Miles / gallon")
"""
def __init__(self, xlab):
if xlab is None:
raise Exception("Arguments to", self.__class__.__name__,
"cannot be None")
self.xlab = xlab
def __radd__(self, gg):
gg = deepcopy(gg)
gg.xlab = self.xlab
return gg
class ylab(object):
"""
Set label for y axis
Parameters
----------
label:
label for your axis
Examples
--------
>>> ggplot(mpg, aes(x='hwy')) + geom_hisotgram() + ylab('''Count\n(# of cars)''')
"""
def __init__(self, ylab):
if ylab is None:
raise Exception("Arguments to", self.__class__.__name__,
"cannot be None")
self.ylab = ylab
def __radd__(self, gg):
gg = deepcopy(gg)
gg.ylab = self.ylab
return gg
class labs(object):
"""
Set labels plot
Parameters
----------
x:
label for your x axis
y:
label for your y axis
title:
title for your plot
Examples
--------
>>> ggplot(mpg, aes(x='hwy')) + geom_hisotgram() + labs("Miles / gallon", '''Count\n(# of cars)''', "MPG Plot")
"""
def __init__(self, x=None, y=None, title=None):
self.x = x
self.y = y
self.title = title
def __radd__(self, gg):
gg = deepcopy(gg)
if self.x:
gg.xlab = self.x
if self.y:
gg.ylab = self.y
if self.title:
gg.title = self.title
return gg
if __name__ == '__main__':
xlab("HI")
ylab("hi")
labs(x="hi", y="boo", title="foo")
ggtitle("hi")