Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit 8e09b8b

Browse files
area plots
1 parent e72a8cf commit 8e09b8b

File tree

5 files changed

+65
-4
lines changed

5 files changed

+65
-4
lines changed

gallery.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ px.line(gapminder, x="year", y="lifeExp", color="continent", line_group="country
115115
line_shape="spline")
116116
```
117117

118+
```python
119+
px.area(gapminder, x="year", y="pop", color="continent", line_group="country")
120+
```
121+
118122
## Visualize Distributions
119123

120124
```python

plotly_express/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
line_ternary,
1919
line_mapbox,
2020
line_geo,
21+
area,
2122
bar,
2223
bar_polar,
2324
violin,
@@ -50,6 +51,7 @@
5051
"line_geo",
5152
"parallel_coordinates",
5253
"parallel_categories",
54+
"area",
5355
"bar",
5456
"bar_polar",
5557
"violin",

plotly_express/_chart_types.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,51 @@ def line(
150150
line.__doc__ = make_docstring(line)
151151

152152

153+
def area(
154+
data_frame,
155+
x=None,
156+
y=None,
157+
line_group=None,
158+
color=None,
159+
hover_name=None,
160+
hover_data=None,
161+
text=None,
162+
facet_row=None,
163+
facet_col=None,
164+
animation_frame=None,
165+
animation_group=None,
166+
category_orders={},
167+
labels={},
168+
color_discrete_sequence=default_qualitative,
169+
color_discrete_map={},
170+
orientation="v",
171+
groupnorm=None,
172+
log_x=False,
173+
log_y=False,
174+
range_x=None,
175+
range_y=None,
176+
line_shape=None,
177+
render_mode="auto",
178+
title=None,
179+
template=default_template,
180+
width=default_width,
181+
height=default_height,
182+
):
183+
"""
184+
In a stacked area plot, each row of `data_frame` is represented as vertex of a polyline mark in 2D space. The area between successive polylines is filled.
185+
"""
186+
return make_figure(
187+
args=locals(),
188+
constructor=go.Scatter,
189+
trace_patch=dict(
190+
stackgroup=1, mode="lines", orientation=orientation, groupnorm=groupnorm
191+
),
192+
)
193+
194+
195+
area.__doc__ = make_docstring(area)
196+
197+
153198
def bar(
154199
data_frame,
155200
x=None,

plotly_express/_core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,8 @@ def infer_config(args, constructor, trace_patch):
581581
+ ["lat", "lon", "locations", "animation_group"]
582582
)
583583

584-
groupables = ["animation_frame", "facet_row", "facet_col", "line_group"]
585-
586584
attrs = [k for k in attrables if k in args]
587-
grouped_attrs = [k for k in groupables if k in args]
585+
grouped_attrs = []
588586

589587
sizeref = 0
590588
if "size" in args and args["size"]:
@@ -645,6 +643,10 @@ def infer_config(args, constructor, trace_patch):
645643
args[position] = args["marginal"]
646644
args[other_position] = None
647645

646+
for k in ["animation_frame", "facet_row", "facet_col", "line_group"]:
647+
if k in args:
648+
grouped_attrs.append(k)
649+
648650
grouped_mappings = [make_mapping(args, a) for a in grouped_attrs]
649651
trace_specs = make_trace_spec(args, constructor, attrs, trace_patch)
650652
return trace_specs, grouped_mappings, sizeref, color_range

plotly_express/_doc.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,21 @@
267267
"If set to `'fraction'`, the value of each bar is divided by the sum of all values at that location coordinate.",
268268
"`'percent'` is the same but multiplied by 100 to show percentages.",
269269
],
270+
groupnorm=[
271+
"(string, one of `'fraction'` or `'percent'`, default is `None`)",
272+
"If set to `'fraction'`, the value of each point is divided by the sum of all values at that location coordinate.",
273+
"`'percent'` is the same but multiplied by 100 to show percentages.",
274+
],
270275
barmode=[
271276
"(string, one of `'group'` or `'relative'`. Default is `'relative'`)",
272277
"In `'relative'` mode, bars are stacked above zero for positive values and below zero for negative values.",
273278
"In `'group'` mode, bars are placed beside each other.",
274279
],
275280
zoom=["(integer between 0 and 20, default is 8)", "Sets map zoom level."],
276-
orientation=["(string, one of `'h'` or `'v'`)", "Default is `'v'`."],
281+
orientation=[
282+
"(string, one of `'h'` for horizontal or `'v' for vertical`)",
283+
"Default is `'v'`.",
284+
],
277285
line_close=[
278286
"(boolean, default `False`)",
279287
"If `True`, an extra line segment is drawn between the first and last point.",

0 commit comments

Comments
 (0)