Skip to content

scatter colorbar ignores boundaries when outside of plot #144

Closed

Description

@bradyrx

Description

When using the plt.scatter wrapper, if some dimension of the data is mapped to color and the color bar placed externally, it is forced into a discrete colorbar and the boundaries cannot be modified. The colorbar features are different if placed inside the plot.

  1. It would be great for this to generally be fixed.
  2. Would it be feasible to add levels to the scatter wrapper?

Steps to reproduce

import numpy as np
import proplot as plot

state = np.random.RandomState(51423)
data = state.rand(2, 100)

f, ax = plot.subplots()
ax.scatter(*data, marker='o', color=data.sum(axis=0), cmap='Marine',
           colorbar='l', vmin=0, vmax=2,
           colorbar_kw={'boundaries': plot.arange(0, 2, 0.01),
                                  'locator': 0.5})

f, ax = plot.subplots()
ax.scatter(*data, marker='o', color=data.sum(axis=0), cmap='Marine',
           colorbar='lr', vmin=0, vmax=2,
           colorbar_kw={'boundaries': plot.arange(0, 2, 0.01),
                                  'locator': 0.5})

In the first bit, I am using boundaries as a hack to get at levels. I want to force this to much smaller colorbar steps, just to prove that it's working. It seems like locator works, but not boundaries for instance.

Screen Shot 2020-04-22 at 2 53 20 PM

In the second bit, when colorbar='lr', it works fine. I.e., when colorbars are inside the plot, the boundaries keyword works. When placed outside (e.g. l, r, b), the colorbar is funky.

Screen Shot 2020-04-22 at 2 52 07 PM

Equivalent steps in matplotlib

The default exterior colorbar in matplotlib looks a lot better (it's continuous without mislabeling of the discrete boundaries), and the boundaries keyword works here.

import matplotlib.pyplot as plt
state = np.random.RandomState(51423)
data = state.rand(2, 100)


f, ax = plt.subplots()
p = ax.scatter(*data, marker='o', c=data.sum(axis=0))

f.colorbar(p, boundaries=plot.arange(0, 2, 0.1))

Screen Shot 2020-04-22 at 2 55 36 PM

Proplot version

0.5.0.post46

Activity

  1. lukelbd commented on Apr 22, 2020

    @lukelbd
    Collaborator

    Thanks for the examples. Unfortunately it looks like this bug was introduced to the dev branch, possibly in commit f83570c. Here is your first example with the last stable release (v0.5.0):

    bug_v5

    And here is the dev branch:

    bug_post46

    For now you can revert back to the last stable release.

  2. lukelbd commented on Apr 22, 2020

    @lukelbd
    Collaborator

    Also I know the Issue page is getting pretty backed up here... I've been really focusing on research these past 2 months. Will try to catch up on these issues by the end of the month at least, then release a new version by early May.

  3. lukelbd commented on Apr 22, 2020

    @lukelbd
    Collaborator

    Re: adding levels to scatter, I 100% support that. Right now it's a little complicated because scatter is wrapped by cycle_changer, and generally plotting functions are wrapped by either cmap_changer (which provides level support) or cycle_changer, not both.

    This may be easier to do after #111 is merged, because then features can be added piecemeal to individual plotting methods like Axes.contourf and Axes.scatter by dispatching to several small, self-contained functions, instead of using these big honking wrapper functions like cmap_changer. The whole "wrapper function" idea is a relic of some of the very first plotting code I wrote for this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions