question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected behavior when explicitly providing colors and unevenly spaced levels

See original GitHub issue

Description

When supplying my own colors and unevenly spaced levels explicitly, I observe an unexpected behavior where some colors are omitted and others are repeated.

Steps to reproduce

import proplot as pplt
import numpy as np

N=20
state=np.random.RandomState(51423)
data=np.cumsum(state.rand(N, N), axis=1)

colors=['white','indigo1','indigo3','indigo5','indigo7','indigo9','yellow1','yellow3','yellow5','yellow7','yellow9','violet1','violet3']

fig,axs=pplt.subplots(nrows=2, ncols=1, refheight=3.5)

axs[0].pcolormesh(data, levels=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
                  colors=colors, colorbar='r', extend='both', colorbar_kw={'label':'Expected color distribution'})

axs[1].pcolormesh(data,levels=[1., 1.25, 1.5, 2., 2.5, 3., 3.75, 4.5, 6., 7.5, 9., 12.],
                  colors=colors, colorbar='r', extend='both', colorbar_kw={'label':'Unexpected color distribution'})

unexpected_behavior

Expected behavior: I expected that all 13 named colors would still show when mapped to the unevenly spaced levels on axs[1].

Actual behavior: In this example on axs[1], some colors are omitted and replaced by others. I also observe this issue when providing my own RGB tuples.

Equivalent steps in matplotlib

Explicitly providing named colors and unevenly spaced levels in Matplotlib gives the desired behavior.

Proplot version

ProPlot 0.9.5 Matplotlib 3.4.3 Python 3.9.7

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
AWSiscocommented, Nov 3, 2021

Thanks for such a quick turnaround on getting this resolved. Much appreciated!

0reactions
lukelbdcommented, Nov 3, 2021

Here’s your example after the update. Note some ticks on the right “linear” colorbar are missing by default (to prevent overcrowding) while ticks on the left SegmentedNorm colorbar are all shown (to avoid hiding the locations of non-linear thresholds in the scaling).

import proplot as pplt
import numpy as np
N=20
state=np.random.RandomState(51423)
data=np.cumsum(state.rand(N, N), axis=1)
colors=['white','indigo1','indigo3','indigo5','indigo7','indigo9','yellow1','yellow3','yellow5','yellow7','yellow9','violet1','violet3']
levels_even = pplt.arange(1,12,1)
levels_uneven=[1., 1.25, 1.5, 2., 2.5, 3., 3.75, 4.5, 6., 7.5, 9., 12.]
fig, axs = pplt.subplots(ncols=2, refwidth=3.)
axs[0].pcolor(np.random.rand(10, 10) * 12, levels=levels_uneven, colors=colors, colorbar='r', extend='both')
axs[1].pcolor(np.random.rand(10, 10) * 12, levels=levels_even, colors=colors, colorbar='r', extend='both')

testing

Read more comments on GitHub >

github_iconTop Results From Across the Web

Color psychology - Wikipedia
Color psychology is the study of hues as a determinant of human behavior. Color influences perceptions that are not obvious, such as the...
Read more >
Color Realism and Color Science
We defend the view that physical objects (for instance, tomatoes, radishes, and rubies) are colored, and that colors are physical properties, specifically ......
Read more >
The Causes and Consequences of Color Vision | Evolution
This paper provides a brief introduction to color vision, the genetics of color vision in humans, what colors other animals see, ...
Read more >
the geometry of color perception - handprint
The Munsell system can be used to define colors that are perceived to be evenly spaced in hue and chroma across equal value...
Read more >
Mouse color and wavelength-specific luminance contrast ...
Here, we use a simple behavior, change detection, to determine where in visual space mice can discriminate changes in chromaticity and luminance at ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found