@@ -287,6 +287,56 @@ fig = go.Figure(data=[go.Bar(
287
287
fig.show()
288
288
```
289
289
290
+ Bar charts with custom widths can be used to make mekko charts (also known as marimekko charts, mosaic plots, or variwide charts).
291
+
292
+ ``` python
293
+ import plotly.graph_objects as go
294
+ import numpy as np
295
+
296
+ labels = [" apples" ," oranges" ," pears" ," bananas" ]
297
+ widths = np.array([10 ,20 ,20 ,50 ])
298
+
299
+ data = {
300
+ " South" : [50 ,80 ,60 ,70 ],
301
+ " North" : [50 ,20 ,40 ,30 ]
302
+ }
303
+
304
+ fig = go.Figure()
305
+ for key in data:
306
+ fig.add_trace(go.Bar(
307
+ name = key,
308
+ y = data[key],
309
+ x = np.cumsum(widths)- widths,
310
+ width = widths,
311
+ offset = 0 ,
312
+ customdata = np.transpose([labels, widths* data[key]]),
313
+ texttemplate = " %{y} x %{width} =<br>%{customdata[1]} " ,
314
+ textposition = " inside" ,
315
+ textangle = 0 ,
316
+ textfont_color = " white" ,
317
+ hovertemplate = " <br>" .join([
318
+ " label: %{customdata[0]} " ,
319
+ " width: %{width} " ,
320
+ " height: %{y} " ,
321
+ " area: %{customdata[1]} " ,
322
+ ])
323
+ ))
324
+
325
+ fig.update_xaxes(
326
+ tickvals = np.cumsum(widths)- widths/ 2 ,
327
+ ticktext = [" %s <br>%d " % (l, w) for l, w in zip (labels, widths)]
328
+ )
329
+
330
+ fig.update_xaxes(range = [0 ,100 ])
331
+ fig.update_yaxes(range = [0 ,100 ])
332
+
333
+ fig.update_layout(
334
+ title_text = " Marimekko Chart" ,
335
+ barmode = " stack" ,
336
+ uniformtext = dict (mode = " hide" , minsize = 10 ),
337
+ )
338
+ ```
339
+
290
340
### Customizing Individual Bar Base
291
341
292
342
``` python
0 commit comments