Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[MNT]: ListedColormap inconsistencies #28763

Closed
@oscargus

Description

@oscargus

Summary

The documentation toListedColormap states that the input should be a list or array

colors : list, array
Sequence of Matplotlib color specifications (color names or RGB(A)
values).

However, when specifyingN,str andfloat are also supported (if one use the source code)

ifisinstance(colors,str):
self.colors= [colors]*N
self.monochrome=True
elifnp.iterable(colors):
iflen(colors)==1:
self.monochrome=True
self.colors=list(
itertools.islice(itertools.cycle(colors),N))
else:
try:
gray=float(colors)
exceptTypeError:
pass
else:
self.colors= [gray]*N
self.monochrome=True

This means that, e.g.,ListedColormap("#aabbcc", N=1) works, butListedColormap("#aabbcc") does not (there will be weird errors later, likeN=7 for the latter). Given that there ismonochrome attribute and the documentation ofN, one may expect the latter to work as well (if the earlier works). Also,ListedColormap(["#aabbcc"]) will not set themonochrome attribute correctly.

Proposed fix

I think there are three(?) possible solutions:

  • Support scalars/strings whenN is not provided (and ideally documents that)
  • Document that ifN is not None, the first argument can be a scalar or string (it is maybe easier to doListedColormap(0.3, N=7) thanListedColormap([0.3]*7) or at least require slightly less Python knowledge)
  • Deprecate scalar/string argument

Bonus: document thecolor andmonochrome attributes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp