8000 enable faceting for geo, geojson everywhere possible, text/symbols fo… by nicolaskruchten · Pull Request #2923 · plotly/plotly.py · GitHub
[go: up one dir, main page]

Skip to content

enable faceting for geo, geojson everywhere possible, text/symbols fo… #2923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use subplot updaters to prep for facets-everywhere
  • Loading branch information
nicolaskruchten committed Nov 21, 2020
commit 01b256bbbee81f416b9e1888db8d64433b5d0be5
5 changes: 3 additions & 2 deletions doc/python/facet-plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ df = df.melt(id_vars="district", value_vars=["Coderre", "Bergeron", "Joly"],
geojson = px.data.election_geojson()

fig = px.choropleth(df, geojson=geojson, color="votes", facet_col="candidate",
locations="district", featureidkey="properties.district"
locations="district", featureidkey="properties.district",
projection="mercator"
)
fig.update_geos(fitbounds="locations", visible=False, projection_type="mercator")
fig.update_geos(fitbounds="locations", visible=False)
fig.show()
```

Expand Down
66 changes: 27 additions & 39 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,33 +616,27 @@ def configure_cartesian_axes(args, fig, orders):
if "is_timeline" in args:
fig.update_xaxes(type="date")

return fig.layout


def configure_ternary_axes(args, fig, orders):
fig.update_layout(
ternary=dict(
aaxis=dict(title_text=get_label(args, args["a"])),
baxis=dict(title_text=get_label(args, args["b"])),
caxis=dict(title_text=get_label(args, args["c"])),
)
fig.update_ternaries(
aaxis=dict(title_text=get_label(args, args["a"])),
baxis=dict(title_text=get_label(args, args["b"])),
caxis=dict(title_text=get_label(args, args["c"])),
)


def configure_polar_axes(args, fig, orders):
layout = dict(
polar=dict(
angularaxis=dict(direction=args["direction"], rotation=args["start_angle"]),
radialaxis=dict(),
)
patch = dict(
angularaxis=dict(direction=args["direction"], rotation=args["start_angle"]),
radialaxis=dict(),
)

for var, axis in [("r", "radialaxis"), ("theta", "angularaxis")]:
if args[var] in orders:
layout["polar"][axis]["categoryorder"] = "array"
layout["polar"][axis]["categoryarray"] = orders[args[var]]
patch[axis]["categoryorder"] = "array"
patch[axis]["categoryarray"] = orders[args[var]]

radialaxis = layout["polar"]["radialaxis"]
radialaxis = patch["radialaxis"]
if args["log_r"]:
radialaxis["type"] = "log"
if args["range_r"]:
Expand All @@ -652,21 +646,19 @@ def configure_polar_axes(args, fig, orders):
radialaxis["range"] = args["range_r"]

if args["range_theta"]:
layout["polar"]["sector"] = args["range_theta"]
fig.update(layout=layout)
patch["sector"] = args["range_theta"]
fig.update_polars(patch)


def configure_3d_axes(args, fig, orders):
layout = dict(
scene=dict(
xaxis=dict(title_text=get_label(args, args["x"])),
yaxis=dict(title_text=get_label(args, args["y"])),
zaxis=dict(title_text=get_label(args, args["z"])),
)
patch = dict(
xaxis=dict(title_text=get_label(args, args["x"])),
yaxis=dict(title_text=get_label(args, args["y"])),
zaxis=dict(title_text=get_label(args, args["z"])),
)

for letter in ["x", "y", "z"]:
axis = layout["scene"][letter + "axis"]
axis = patch[letter + "axis"]
if args["log_" + letter]:
axis["type"] = "log"
if args["range_" + letter]:
Expand All @@ -677,7 +669,7 @@ def configure_3d_axes(args, fig, orders):
if args[letter] in orders:
axis["categoryorder"] = "array"
axis["categoryarray"] = orders[args[letter]]
fig.update(layout=layout)
fig.update_scenes(patch)


def configure_mapbox(args 935A , fig, orders):
Expand All @@ -687,23 +679,19 @@ def configure_mapbox(args, fig, orders):
lat=args["data_frame"][args["lat"]].mean(),
lon=args["data_frame"][args["lon"]].mean(),
)
fig.update_layout(
mapbox=dict(
accesstoken=MAPBOX_TOKEN,
center=center,
zoom=args["zoom"],
style=args["mapbox_style"],
)
fig.update_mapboxes(
accesstoken=MAPBOX_TOKEN,
center=center,
zoom=args["zoom"],
style=args["mapbox_style"],
)


def configure_geo(args, fig, orders):
fig.update_layout(
geo=dict(
center=args["center"],
scope=args["scope"],
projection=dict(type=args["projection"]),
)
fig.update_geos(
center=args["center"],
scope=args["scope"],
projection=dict(type=args["projection"]),
)


Expand Down
0