Skip to content

Commit

Permalink
Merge pull request #1109 from gboeing/plot
Browse files Browse the repository at this point in the history
deprecate return_hex argument
  • Loading branch information
gboeing authored Jan 12, 2024
2 parents 8e32e32 + 7d296f1 commit 18a1746
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
## Unreleased

- fix a bug in the features module's polygon handling (#1104)
- fix deprecated numpy random number generation (#1108)
- update obsolete numpy random number generation (#1108)
- deprecate return_coords argument in graph.graph_from_address function (#1105)
- deprecate return_hex argument in plot.get_colors function (#1109)

## 1.8.1 (2023-12-31)

Expand Down
28 changes: 22 additions & 6 deletions osmnx/plot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Visualize street networks, routes, orientations, and geospatial features."""

from pathlib import Path
from warnings import warn

import networkx as nx
import numpy as np
Expand Down Expand Up @@ -40,21 +41,36 @@ def get_colors(n, cmap="viridis", start=0.0, stop=1.0, alpha=1.0, return_hex=Fal
stop : float
where to end in the colorspace
alpha : float
opacity, the alpha channel for the RGBa colors
If `None`, return colors as HTML-like hex triplet "#rrggbb" RGB
strings. If `float`, return as "#rrggbbaa" RGBa strings.
return_hex : bool
if True, convert RGBa colors to HTML-like hexadecimal RGB strings. if
False, return colors as (R, G, B, alpha) tuples.
deprecated, do not use
Returns
-------
color_list : list
"""
if return_hex is None:
return_hex = False
else:
warn(
"The `return_hex` function has been deprecated and will be removed "
"in the v2.0.0 release.",
stacklevel=2,
)

_verify_mpl()

color_list = [colormaps[cmap](x) for x in np.linspace(start, stop, n)]
if return_hex:
color_list = [colors.to_hex(c) for c in color_list]
else:
keep_alpha = alpha is not None
if keep_alpha:
color_list = [(r, g, b, alpha) for r, g, b, _ in color_list]
else:
color_list = [(r, g, b) for r, g, b, _ in color_list]

if return_hex:
return [colors.to_hex(c, keep_alpha=keep_alpha) for c in color_list]

return color_list


Expand Down

0 comments on commit 18a1746

Please sign in to comment.