Skip to content

⚡️ Speed up function convert_rgba_array by 65% #5244

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
13 changes: 5 additions & 8 deletions plotly/matplotlylib/mpltools.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,11 @@ def get_bar_gap(bar_starts, bar_ends, tol=1e-10):


def convert_rgba_array(color_list):
clean_color_list = list()
for c in color_list:
clean_color_list += [
dict(r=int(c[0] * 255), g=int(c[1] * 255), b=int(c[2] * 255), a=c[3])
]
plotly_colors = list()
for rgba in clean_color_list:
plotly_colors += ["rgba({r},{g},{b},{a})".format(**rgba)]
# Use a single list comprehension to both process and format the color list
plotly_colors = [
f"rgba({int(c[0] * 255)},{int(c[1] * 255)},{int(c[2] * 255)},{c[3]})"
for c in color_list
]
if len(plotly_colors) == 1:
return plotly_colors[0]
else:
Expand Down