@@ -160,14 +160,15 @@ def _bullet(df, markers, measures, ranges, subtitles, titles, orientation,
160
160
161
161
def create_bullet (data , markers = None , measures = None , ranges = None ,
162
162
subtitles = None , titles = None , orientation = 'h' ,
163
- range_colors = None , measure_colors = None ,
163
+ range_colors = ('rgb(200, 200, 200)' , 'rgb(245, 245, 245)' ),
164
+ measure_colors = ('rgb(31, 119, 180)' , 'rgb(176, 196, 221)' ),
164
165
horizontal_spacing = None , vertical_spacing = None ,
165
166
scatter_options = {}, ** layout_options ):
166
167
"""
167
168
Returns figure for bullet chart.
168
169
169
- :param (pd.DataFrame | list) data: either a JSON list of dicts or a pandas
170
- DataFrame.
170
+ :param (pd.DataFrame | list | tuple ) data: either a list/tuple of
171
+ dictionaries or a pandas DataFrame.
171
172
:param (str) markers: the column name or dictionary key for the markers in
172
173
each subplot.
173
174
:param (str) measures: the column name or dictionary key for the measure
@@ -184,14 +185,14 @@ def create_bullet(data, markers=None, measures=None, ranges=None,
184
185
of each subplot chart.
185
186
:param (bool) orientation: if 'h', the bars are placed horizontally as
186
187
rows. If 'v' the bars are placed vertically in the chart.
187
- :param (list) range_colors: a list of two colors between which all
188
+ :param (list) range_colors: a tuple of two colors between which all
188
189
the rectangles for the range are drawn. These rectangles are meant to
189
190
be qualitative indicators against which the marker and measure bars
190
191
are compared.
191
- Default=[ 'rgb(198, 198, 198 )', 'rgb(248, 248, 248)']
192
- :param (list) measure_colors: a list of two colors which is used to color
192
+ Default=( 'rgb(200, 200, 200 )', 'rgb(245, 245, 245)')
193
+ :param (list) measure_colors: a tuple of two colors which is used to color
193
194
the thin quantitative bars in the bullet chart.
194
- Default=[ 'rgb(31, 119, 180)', 'rgb(176, 196, 221)']
195
+ Default=( 'rgb(31, 119, 180)', 'rgb(176, 196, 221)')
195
196
:param (float) horizontal_spacing: see the 'horizontal_spacing' param in
196
197
plotly.tools.make_subplots. Ranges between 0 and 1.
197
198
:param (float) vertical_spacing: see the 'vertical_spacing' param in
@@ -210,20 +211,22 @@ def create_bullet(data, markers=None, measures=None, ranges=None,
210
211
import plotly.figure_factory as ff
211
212
212
213
data = [
213
- {"e": "Revenue", "d": "US$, in thousands", "c": [150, 225, 300],
214
- "b": [220,270], "a": [250]},
215
- {"e": "Profit", "d": "%", "c": [20, 25, 30], "b": [21, 23], "a": [26]},
216
- {"e": "Order Size", "d":"US$, average","c": [350, 500, 600],
217
- "b": [100,320],"a": [550]},
218
- {"e": "New Customers", "d": "count", "c": [1400, 2000, 2500],
219
- "b": [1000,1650],"a": [2100]},
220
- {"e": "Satisfaction", "d": "out of 5","c": [3.5, 4.25, 5],
221
- "b": [3.2,4.7], "a": [4.4]}
214
+ {"label": "Revenue", "sublabel": "US$, in thousands",
215
+ "range": [150, 225, 300], "performance": [220,270], "point": [250]},
216
+ {"label": "Profit", "sublabel": "%", "range": [20, 25, 30],
217
+ "performance": [21, 23], "point": [26]},
218
+ {"label": "Order Size", "sublabel":"US$, average","range": [350, 500, 600],
219
+ "performance": [100,320],"point": [550]},
220
+ {"label": "New Customers", "sublabel": "count", "range": [1400, 2000, 2500],
221
+ "performance": [1000, 1650],"point": [2100]},
222
+ {"label": "Satisfaction", "sublabel": "out of 5","range": [3.5, 4.25, 5],
223
+ "performance": [3.2, 4.7], "point": [4.4]}
222
224
]
223
225
224
226
fig = ff.create_bullet(
225
- data, titles='e', subtitles='d', markers='a', measures='b',
226
- ranges='c', orientation='h', title='my simple bullet chart'
227
+ data, titles='label', subtitles='sublabel', markers='point',
228
+ measures='performance', ranges='range', orientation='h',
229
+ title='my simple bullet chart'
227
230
)
228
231
py.iplot(fig)
229
232
```
@@ -249,23 +252,25 @@ def create_bullet(data, markers=None, measures=None, ranges=None,
249
252
# validate df
250
253
if not pd :
251
254
raise exceptions .ImportError (
252
- "'pandas' must be imported for this figure_factory ."
255
+ "'pandas' must be installed for this figure factory ."
253
256
)
254
257
255
- if isinstance (data , list ):
258
+ if isinstance (data , ( tuple , list ) ):
256
259
if not all (isinstance (item , dict ) for item in data ):
257
260
raise exceptions .PlotlyError (
258
- 'If your data is a list, all entries must be dictionaries.'
261
+ 'Every entry of the data argument (a list or tuple) must be '
262
+ 'a dictionary.'
259
263
)
260
264
261
265
elif not isinstance (data , pd .DataFrame ):
262
266
raise exceptions .PlotlyError (
263
- 'You must input a pandas DataFrame or a list of dictionaries.'
267
+ 'You must input a pandas DataFrame, or a list or tuple of '
268
+ 'dictionaries.'
264
269
)
265
270
266
271
# make DataFrame from data with correct column headers
267
272
col_names = ['titles' , 'subtitle' , 'markers' , 'measures' , 'ranges' ]
268
- if isinstance (data , list ):
273
+ if isinstance (data , ( tuple , list ) ):
269
274
df = pd .DataFrame (
270
275
[
271
276
[d [titles ] for d in data ] if titles else ['' ] * len (data ),
0 commit comments