forked from plotly/plotly.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_ybins.py
240 lines (214 loc) · 9.45 KB
/
_ybins.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
from plotly.basedatatypes import BaseTraceHierarchyType
import copy
class YBins(BaseTraceHierarchyType):
# end
# ---
@property
def end(self):
"""
Sets the end value for the y axis bins. The last bin may not
end exactly at this value, we increment the bin edge by `size`
from `start` until we reach or exceed `end`. Defaults to the
maximum data value. Like `start`, for dates use a date string,
and for category data `end` is based on the category serial
numbers.
The 'end' property accepts values of any type
Returns
-------
Any
"""
return self['end']
@end.setter
def end(self, val):
self['end'] = val
# size
# ----
@property
def size(self):
"""
Sets the size of each y axis bin. Default behavior: If `nbinsy`
is 0 or omitted, we choose a nice round bin size such that the
number of bins is about the same as the typical number of
samples in each bin. If `nbinsy` is provided, we choose a nice
round bin size giving no more than that many bins. For date
data, use milliseconds or "M<n>" for months, as in
`axis.dtick`. For category data, the number of categories to
bin together (always defaults to 1). If multiple non-overlaying
histograms share a subplot, the first explicit `size` is used
and all others discarded. If no `size` is provided,the sample
data from all traces is combined to determine `size` as
described above.
The 'size' property accepts values of any type
Returns
-------
Any
"""
return self['size']
@size.setter
def size(self, val):
self['size'] = val
# start
# -----
@property
def start(self):
"""
Sets the starting value for the y axis bins. Defaults to the
minimum data value, shifted down if necessary to make nice
round values and to remove ambiguous bin edges. For example, if
most of the data is integers we shift the bin edges 0.5 down,
so a `size` of 5 would have a default `start` of -0.5, so it is
clear that 0-4 are in the first bin, 5-9 in the second, but
continuous data gets a start of 0 and bins [0,5), [5,10) etc.
Dates behave similarly, and `start` should be a date string.
For category data, `start` is based on the category serial
numbers, and defaults to -0.5. If multiple non-overlaying
histograms share a subplot, the first explicit `start` is used
exactly and all others are shifted down (if necessary) to
differ from that one by an integer number of bins.
The 'start' property accepts values of any type
Returns
-------
Any
"""
return self['start']
@start.setter
def start(self, val):
self['start'] = val
# property parent name
# --------------------
@property
def _parent_path_str(self):
return 'histogram'
# Self properties description
# ---------------------------
@property
def _prop_descriptions(self):
return """\
end
Sets the end value for the y axis bins. The last bin
may not end exactly at this value, we increment the bin
edge by `size` from `start` until we reach or exceed
`end`. Defaults to the maximum data value. Like
`start`, for dates use a date string, and for category
data `end` is based on the category serial numbers.
size
Sets the size of each y axis bin. Default behavior: If
`nbinsy` is 0 or omitted, we choose a nice round bin
size such that the number of bins is about the same as
the typical number of samples in each bin. If `nbinsy`
is provided, we choose a nice round bin size giving no
more than that many bins. For date data, use
milliseconds or "M<n>" for months, as in `axis.dtick`.
For category data, the number of categories to bin
together (always defaults to 1). If multiple non-
overlaying histograms share a subplot, the first
explicit `size` is used and all others discarded. If no
`size` is provided,the sample data from all traces is
combined to determine `size` as described above.
start
Sets the starting value for the y axis bins. Defaults
to the minimum data value, shifted down if necessary to
make nice round values and to remove ambiguous bin
edges. For example, if most of the data is integers we
shift the bin edges 0.5 down, so a `size` of 5 would
have a default `start` of -0.5, so it is clear that 0-4
are in the first bin, 5-9 in the second, but continuous
data gets a start of 0 and bins [0,5), [5,10) etc.
Dates behave similarly, and `start` should be a date
string. For category data, `start` is based on the
category serial numbers, and defaults to -0.5. If
multiple non-overlaying histograms share a subplot, the
first explicit `start` is used exactly and all others
are shifted down (if necessary) to differ from that one
by an integer number of bins.
"""
def __init__(self, arg=None, end=None, size=None, start=None, **kwargs):
"""
Construct a new YBins object
Parameters
----------
arg
dict of properties compatible with this constructor or
an instance of plotly.graph_objs.histogram.YBins
end
Sets the end value for the y axis bins. The last bin
may not end exactly at this value, we increment the bin
edge by `size` from `start` until we reach or exceed
`end`. Defaults to the maximum data value. Like
`start`, for dates use a date string, and for category
data `end` is based on the category serial numbers.
size
Sets the size of each y axis bin. Default behavior: If
`nbinsy` is 0 or omitted, we choose a nice round bin
size such that the number of bins is about the same as
the typical number of samples in each bin. If `nbinsy`
is provided, we choose a nice round bin size giving no
more than that many bins. For date data, use
milliseconds or "M<n>" for months, as in `axis.dtick`.
For category data, the number of categories to bin
together (always defaults to 1). If multiple non-
overlaying histograms share a subplot, the first
explicit `size` is used and all others discarded. If no
`size` is provided,the sample data from all traces is
combined to determine `size` as described above.
start
Sets the starting value for the y axis bins. Defaults
to the minimum data value, shifted down if necessary to
make nice round values and to remove ambiguous bin
edges. For example, if most of the data is integers we
shift the bin edges 0.5 down, so a `size` of 5 would
have a default `start` of -0.5, so it is clear that 0-4
are in the first bin, 5-9 in the second, but continuous
data gets a start of 0 and bins [0,5), [5,10) etc.
Dates behave similarly, and `start` should be a date
string. For category data, `start` is based on the
category serial numbers, and defaults to -0.5. If
multiple non-overlaying histograms share a subplot, the
first explicit `start` is used exactly and all others
are shifted down (if necessary) to differ from that one
by an integer number of bins.
Returns
-------
YBins
"""
super(YBins, self).__init__('ybins')
# Validate arg
# ------------
if arg is None:
arg = {}
elif isinstance(arg, self.__class__):
arg = arg.to_plotly_json()
elif isinstance(arg, dict):
arg = copy.copy(arg)
else:
raise ValueError(
"""\
The first argument to the plotly.graph_objs.histogram.YBins
constructor must be a dict or
an instance of plotly.graph_objs.histogram.YBins"""
)
# Handle skip_invalid
# -------------------
self._skip_invalid = kwargs.pop('skip_invalid', False)
# Import validators
# -----------------
from plotly.validators.histogram import (ybins as v_ybins)
# Initialize validators
# ---------------------
self._validators['end'] = v_ybins.EndValidator()
self._validators['size'] = v_ybins.SizeValidator()
self._validators['start'] = v_ybins.StartValidator()
# Populate data dict with properties
# ----------------------------------
_v = arg.pop('end', None)
self['end'] = end if end is not None else _v
_v = arg.pop('size', None)
self['size'] = size if size is not None else _v
_v = arg.pop('start', None)
self['start'] = start if start is not None else _v
# Process unknown kwargs
# ----------------------
self._process_kwargs(**dict(arg, **kwargs))
# Reset skip_invalid
# ------------------
self._skip_invalid = False