Skip to content

Pass rc.cmap and rc.cycle arguments through respective constructor functions #169

Closed

Description

@zxdawn

Description

Since cycle supports cmaps, the input of cmap name in the configuration should be supported.

Steps to reproduce

import proplot as plot
import numpy as np

fig, axs = plot.subplots()
state = np.random.RandomState(51423)
data = (20 * state.rand(10, 21) - 10).cumsum(axis=0)

plot.rc.update({'cycle': 'plum', 'lines.linewidth': '5'})
lines = axs.plot(data[:, :5])

Expected behavior:
Like:

plot.rc.update({'lines.linewidth': '5'})
lines = axs.plot(data[:, :5], cycle='plum')

cmap

Actual behavior: [What actually happened]

Traceback (most recent call last):
  File "/home/xin/Desktop/test.py", line 11, in <module>
    plot.rc.update({'cycle': 'plum', 'lines.linewidth': '5'})
  File "/home/xin/Documents/Github/proplot/proplot/config.py", line 906, in update
    self.__setitem__(prefix + key, value)
  File "/home/xin/Documents/Github/proplot/proplot/config.py", line 410, in __setitem__
    kw_quick, kw_added, kw_params = self._get_param_dicts(key, value)
  File "/home/xin/Documents/Github/proplot/proplot/config.py", line 490, in _get_param_dicts
    colors = _get_cycle_colors(value)
  File "/home/xin/Documents/Github/proplot/proplot/config.py", line 1020, in _get_cycle_colors
    + ', '.join(map(repr, cycles)) + '.'
ValueError: Invalid cycle name 'plum'. Options are: '538', 'accent', 'classic', 'colorblind', 'colorblind10', 'dark2', 'default', 'flatui', 'ggplot', 'paired', 'pastel1', 'pastel2', 'qual1', 'qual2', 'set1', 'set2', 'set3', 'tab10', 'tab20', 'tab20b', 'tab20c'.

Proplot version

master branch

Activity

  1. changed the title [-]cmap name doesn't work in the configuration of cycle[/-] [+]Pass rc.cmap and rc.cycle arguments through respective constructor functions[/+] on May 19, 2020
  2. added this to the Version 0.8 milestone on Jul 21, 2021
  3. lukelbd commented on Jul 30, 2021

    @lukelbd
    Collaborator

    I'm going to close this as a duplicate of #69. When I add rc-param assignment validation it will be trivial to pass assignments to rc.cmap and rc.cycle through the Colormap and Cycle constructors.

  4. lukelbd commented on Aug 18, 2021

    @lukelbd
    Collaborator

    Now that rc settings are validated, this has been implemented. It works by saving the colormap name to the rc dict (necessary since the rc dicts should only contain settings printable to proplotrc files). For example:

    pplt.rc.cmap = pplt.Colormap('magma')
    print(pplt.rc.cmap)

    returns 'magma' rather than a colormap instance. This is ok since colormaps assigned to these settings are also automatically registered.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions