Skip to content

Commit

Permalink
Plotly update (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
figuetbe authored Dec 18, 2024
1 parent 6cb5402 commit 7251e36
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
16 changes: 8 additions & 8 deletions docs/visualize/plotly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ traffic provides the same interface as the :meth:`plotly.express` module on
the :class:`~traffic.core.Flight` and :class:`~traffic.core.Traffic` classes.
All kwargs arguments are passed directly to the corresponding method.

- with :func:`plotly.express.line_mapbox`:
- with :func:`plotly.express.line_map`:

.. jupyter-execute::

from traffic.data.samples import belevingsvlucht

belevingsvlucht.line_mapbox(color="callsign")
belevingsvlucht.line_map(color="callsign")

- with :func:`plotly.express.scatter_mapbox`:
- with :func:`plotly.express.scatter_map`:

.. jupyter-execute::

from traffic.data.samples import belevingsvlucht

fig = belevingsvlucht.scatter_mapbox(
fig = belevingsvlucht.scatter_map(
color="altitude", width=600, height=600, zoom=6
)
fig.update_layout(margin=dict(l=50, r=0, t=40, b=40))
Expand All @@ -49,7 +49,7 @@ All kwargs arguments are passed directly to the corresponding method.

from traffic.data.samples import belevingsvlucht

belevingsvlucht.resample("1 min").scatter_mapbox(
belevingsvlucht.resample("1 min").scatter_map(
color="vertical_rate",
range_color=[-4000, 4000],
animation_frame="timestamp",
Expand All @@ -69,7 +69,7 @@ It is also possible to combine elements by constructing a

# fig = go.Figure() # if necessary, we can initiate a Figure and fill it later

fig = belevingsvlucht.resample("1 min").scatter_mapbox(
fig = belevingsvlucht.resample("1 min").scatter_map(
color="vertical_rate",
range_color=[-2000, 2000],
animation_frame="timestamp",
Expand Down Expand Up @@ -109,13 +109,13 @@ Or by combining several traces:
assert subset is not None


fig = subset.scatter_mapbox(
fig = subset.scatter_map(
color="callsign",
hover_data="altitude",
animation_frame="timestamp",
center=airports["LFPO"].latlon_dict,
)
fig = fig.add_traces(subset.line_mapbox(
fig = fig.add_traces(subset.line_map(
color="callsign",
).data)
fig.update_layout(margin=dict(l=0, r=0, t=0, b=0))
Expand Down
22 changes: 11 additions & 11 deletions src/traffic/core/flight.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class Flight(
:meth:`geoencode`
- visualisation with leaflet: :meth:`map_leaflet`
- visualisation with plotly: :meth:`line_mapbox` and others
- visualisation with plotly: :meth:`line_map` and others
- visualisation with Matplotlib:
:meth:`plot`,
:meth:`plot_time`
Expand Down Expand Up @@ -2998,16 +2998,16 @@ def map_leaflet(
def line_geo(self, **kwargs: Any) -> "go.Figure":
raise ImportError("Install plotly or traffic with the plotly extension")

def line_mapbox(
self, mapbox_style: str = "carto-positron", **kwargs: Any
def line_map(
self, map_style: str = "carto-positron", **kwargs: Any
) -> "go.Figure":
raise ImportError("Install plotly or traffic with the plotly extension")

def scatter_geo(self, **kwargs: Any) -> "go.Figure":
raise ImportError("Install plotly or traffic with the plotly extension")

def scatter_mapbox(
self, mapbox_style: str = "carto-positron", **kwargs: Any
def scatter_map(
self, map_style: str = "carto-positron", **kwargs: Any
) -> "go.Figure":
raise ImportError("Install plotly or traffic with the plotly extension")

Expand Down Expand Up @@ -3145,16 +3145,16 @@ def from_file(cls, filename: Union[Path, str], **kwargs: Any) -> Self:
def patch_plotly() -> None:
from ..visualize.plotly import (
Scattergeo,
Scattermapbox,
Scattermap,
line_geo,
line_mapbox,
line_map,
scatter_geo,
scatter_mapbox,
scatter_map,
)

Flight.line_mapbox = line_mapbox # type: ignore
Flight.scatter_mapbox = scatter_mapbox # type: ignore
Flight.Scattermapbox = Scattermapbox # type: ignore
Flight.line_map = line_map # type: ignore
Flight.scatter_map = scatter_map # type: ignore
Flight.Scattermap = Scattermap # type: ignore
Flight.line_geo = line_geo # type: ignore
Flight.scatter_geo = scatter_geo # type: ignore
Flight.Scattergeo = Scattergeo # type: ignore
Expand Down
20 changes: 10 additions & 10 deletions src/traffic/core/traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,16 +1091,16 @@ def map_leaflet(
def line_geo(self, **kwargs: Any) -> "go.Figure":
raise ImportError("Install plotly or traffic with the plotly extension")

def line_mapbox(
self, mapbox_style: str = "carto-positron", **kwargs: Any
def line_map(
self, map_style: str = "carto-positron", **kwargs: Any
) -> "go.Figure":
raise ImportError("Install plotly or traffic with the plotly extension")

def scatter_geo(self, **kwargs: Any) -> "go.Figure":
raise ImportError("Install plotly or traffic with the plotly extension")

def scatter_mapbox(
self, mapbox_style: str = "carto-positron", **kwargs: Any
def scatter_map(
self, map_style: str = "carto-positron", **kwargs: Any
) -> "go.Figure":
raise ImportError("Install plotly or traffic with the plotly extension")

Expand Down Expand Up @@ -1527,16 +1527,16 @@ def centroid(
def patch_plotly() -> None:
from ..visualize.plotly import (
Scattergeo,
Scattermapbox,
Scattermap,
line_geo,
line_mapbox,
line_map,
scatter_geo,
scatter_mapbox,
scatter_map,
)

Traffic.line_mapbox = line_mapbox # type: ignore
Traffic.scatter_mapbox = scatter_mapbox # type: ignore
Traffic.Scattermapbox = Scattermapbox # type: ignore
Traffic.line_map = line_map # type: ignore
Traffic.scatter_map = scatter_map # type: ignore
Traffic.Scattermap = Scattermap # type: ignore
Traffic.line_geo = line_geo # type: ignore
Traffic.scatter_geo = scatter_geo # type: ignore
Traffic.Scattergeo = Scattergeo # type: ignore
Expand Down
24 changes: 12 additions & 12 deletions src/traffic/visualize/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import plotly.graph_objects as go


def line_mapbox(
def line_map(
self: Any,
mapbox_style: str = "carto-positron",
map_style: str = "carto-positron",
**kwargs: Any,
) -> go.Figure:
"""Create a line plot with Plotly.
Expand All @@ -17,17 +17,17 @@ def line_mapbox(
if (point := getattr(self, "point", None)) is not None:
kwargs["center"] = point.latlon_dict

return px.line_mapbox(
return px.line_map(
self.data,
lat="latitude",
lon="longitude",
mapbox_style=mapbox_style,
map_style=map_style,
**kwargs,
)


def scatter_mapbox(
self: Any, mapbox_style: str = "carto-positron", **kwargs: Any
def scatter_map(
self: Any, map_style: str = "carto-positron", **kwargs: Any
) -> go.Figure:
"""Create a scatter plot with Plotly.
Expand All @@ -37,21 +37,21 @@ def scatter_mapbox(
if (point := getattr(self, "point", None)) is not None:
kwargs["center"] = point.latlon_dict

return px.scatter_mapbox(
return px.scatter_map(
self.data,
lat="latitude",
lon="longitude",
mapbox_style=mapbox_style,
map_style=map_style,
**kwargs,
)


def Scattermapbox(self: Any, **kwargs: Any) -> go.Scattermapbox:
"""Create a Scattermapbox with Plotly.
def Scattermap(self: Any, **kwargs: Any) -> go.Scattermap:
"""Create a Scattermap with Plotly.
Requires the plotly package (optional dependency).
"""
return go.Scattermapbox(
return go.Scattermap(
lat=self.data.latitude,
lon=self.data.longitude,
**kwargs,
Expand Down Expand Up @@ -93,7 +93,7 @@ def scatter_geo(self: Any, **kwargs: Any) -> go.Figure:


def Scattergeo(self: Any, **kwargs: Any) -> go.Scattergeo:
"""Create a Scattermapbox with Plotly.
"""Create a Scattergeo with Plotly.
Requires the plotly package (optional dependency).
"""
Expand Down

0 comments on commit 7251e36

Please sign in to comment.