Skip to content

Commit

Permalink
Merge pull request #3193 from plotly/fix_sample_colorscale
Browse files Browse the repository at this point in the history
Fix sample colorscale
  • Loading branch information
nicolaskruchten authored May 11, 2021
2 parents 2a59bc0 + a33826d commit 5e327e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
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,
)

0 comments on commit 5e327e7

Please sign in to comment.