Skip to content
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

Fix sample colorscale #3193

Merged
merged 2 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions packages/python/plotly/_plotly_utils/colors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,8 @@ def get_colorscale(name):
raise exceptions.PlotlyError(f"Colorscale {name} is not a built-in scale.")

if should_reverse:
return colorscale[::-1]
return colorscale
colorscale = colorscale[::-1]
return make_colorscale(colorscale)


def sample_colorscale(colorscale, samplepoints, low=0.0, high=1.0, colortype="rgb"):
Expand Down
2 changes: 2 additions & 0 deletions packages/python/plotly/plotly/express/colors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@
"plotlyjs",
"DEFAULT_PLOTLY_COLORS",
"PLOTLY_SCALES",
"get_colorscale",
"sample_colorscale",
]
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,29 @@ def test_get_colorscale(self):
self.assertRaisesRegex(PlotlyError, pattern, colors.get_colorscale, name)

# test non-capitalised access
self.assertEqual(colors.sequential.haline, colors.get_colorscale("haline"))
self.assertEqual(
colors.make_colorscale(colors.sequential.haline),
colors.get_colorscale("haline"),
)
# test capitalised access
self.assertEqual(colors.diverging.Earth, colors.get_colorscale("Earth"))
self.assertEqual(
colors.make_colorscale(colors.diverging.Earth),
colors.get_colorscale("Earth"),
)
# test accessing non-capitalised scale with capitalised name
self.assertEqual(colors.cyclical.mrybm, colors.get_colorscale("Mrybm"))
self.assertEqual(
colors.make_colorscale(colors.cyclical.mrybm),
colors.get_colorscale("Mrybm"),
)
# test accessing capitalised scale with non-capitalised name
self.assertEqual(colors.sequential.Viridis, colors.get_colorscale("viridis"))
self.assertEqual(
colors.make_colorscale(colors.sequential.Viridis),
colors.get_colorscale("viridis"),
)
# test accessing reversed scale
self.assertEqual(
colors.diverging.Portland_r, colors.get_colorscale("portland_r")
colors.make_colorscale(colors.diverging.Portland_r),
colors.get_colorscale("portland_r"),
)

def test_sample_colorscale(self):
Expand Down Expand Up @@ -194,3 +207,7 @@ def test_sample_colorscale(self):
defined_colors, samplepoints, colortype="tuple"
)
self.assertEqual(expected_output, output)

self.assertEqual(
colors.sample_colorscale("TuRbId_r", 12), colors.sequential.turbid_r,
)