Coder Social home page Coder Social logo

colormap's Introduction

COLORMAP documentation

Please see : http://colormap.readthedocs.io/ for an up-to-date documentation.

https://github.com/cokelaer/colormap/actions/workflows/ci.yml/badge.svg?branch=main https://coveralls.io/repos/cokelaer/colormap/badge.png?branch=main
version:Python 3.8, 3.9, 3.10, 3.11, 3.12
contributions:Please join https://github.com/cokelaer/colormap
issues:Please use https://github.com/cokelaer/colormap/issues
notebook:Please see https://github.com/cokelaer/colormap/tree/main/notebooks

What is it ?

colormap package provides simple utilities to convert colors between RGB, HEX, HLS, HUV and a class to easily build colormaps for matplotlib. All matplotlib colormaps and some R colormaps are available altogether. The plot_colormap method (see below) is handy to quickly pick up a colormaps and the test_colormap is useful to see test a new colormap.

Installation

pip install colormap

Example

  • Create your own colormap from red to green colors with intermediate color as whitish (diverging map from red to green):

    c = Colormap()
    mycmap = c.cmap( {'red':[1,1,0], 'green':[0,1,.39], 'blue':[0,1,0]})
    cmap = c.test_colormap(mycmap)
    
  • Even simpler if the colormap is linear:

    c = Colormap()
    mycmap = c.cmap_linear('red', 'white', 'green(w3c)')
    cmap = c.test_colormap(mycmap)
    

https://colormap.readthedocs.io/en/latest/_images/quickstart-6.png

  • check out the available colormaps:

    c = Colormap()
    c.plot_colormap('diverging')
    

https://colormap.readthedocs.io/en/latest/_images/quickstart-4.png

See online documentation for details: http://colormap.readthedocs.io/

changelog

Version Description
1.1.0
  • switch to pyproject. remove easydev dependency. compat for python 3.11 and 3.12
1.0.6
  • Fix a matplotlib deprecation
  • Fix RTD documentation
1.0.5
  • remove Python3.6 and added Python3.10 to CI action
  • Fix issue in setup reported in #14
  • add requirements in MANIFEST
  • applied black on all files

colormap's People

Contributors

akronix avatar cokelaer avatar erikjandevries avatar eumiro avatar mshriver avatar mvrozanti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

colormap's Issues

name provided nipy_spectral is not recognised when trying to build for Python 3.8

Hi,
Debian is moving to Python3.8 and I'm trying to update the Debian package of colormap. Unfortunately I get a build time test error:

test_get_cmap.test_get_cmap ... ERROR

======================================================================
ERROR: test_get_cmap.test_get_cmap
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/build/python-colormap-1.0.2/.pybuild/cpython3_3.8_colormap/build/test/test_get_cmap.py", line 7, in test_get_cmap
    get_cmap("nipy_spectral")
  File "/build/python-colormap-1.0.2/.pybuild/cpython3_3.8_colormap/build/colormap/get_cmap.py", line 57, in cmap_builder
    raise ValueError(txt)
ValueError: name provided nipy_spectral is not recognised.
 valid name can be found in colormap.colormap_names

----------------------------------------------------------------------
Ran 13 tests in 0.168s

FAILED (errors=1)

Any idea how to fix this?
BTW, it would help if you would tag colormap releases also on Github (not only on PyPI).
Kind regards; Andreas.

how to build colormap

hello, i confused about how to create a colormap using the exists colormap like 'RdYIGn', and then i want to give it a value, and it come back me a color value, so i can use this color to opencv for draw points.
The purpose i use colormap is to enable my points'color change according to it's x value.
Thanks!

matplotlib 3.1.0 removed mlab

https://matplotlib.org/3.1.0/api/api_changes.html#matplotlib-mlab-removals

This leads to errors like

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-515-01410588794d> in <module>
      1 mycmap = c.cmap_linear('red', 'white', 'green(w3c)')
----> 2 c.test_colormap(mycmap)

~/miniconda3/envs/cfd/lib/python3.7/site-packages/colormap/colors.py in test_colormap(self, cmap)
    932             cmap = self.get_cmap_heat()
    933         import numpy as np
--> 934         from pylab import clf, pcolor, colorbar, show, linspace, axis
    935         A, B = np.meshgrid(linspace(0, 10, 100), linspace(0, 10, 100))
    936         clf()

~/miniconda3/envs/cfd/lib/python3.7/site-packages/pylab.py in <module>
----> 1 from matplotlib.pylab import *
      2 import matplotlib.pylab
      3 __doc__ = matplotlib.pylab.__doc__

~/miniconda3/envs/cfd/lib/python3.7/site-packages/matplotlib/pylab.py in <module>
    231 ## We are still importing too many things from mlab; more cleanup is needed.
    232 
--> 233 from matplotlib.mlab import (
    234     amap, base_repr, binary_repr, bivariate_normal, center_matrix, csv2rec,
    235     demean, detrend, detrend_linear, detrend_mean, detrend_none, dist,

ImportError: cannot import name 'amap' from 'matplotlib.mlab' (~/miniconda3/envs/cfd/lib/python3.7/site-packages/matplotlib/mlab.py)

Documentation graphic.

Thank you for this module.

The second example image appears to have white around 'center' of the image instead of black as specified.
https://pypi.python.org/pypi/colormap

from colormap import Colormap
c = Colormap()
mycmap = c.cmap_linear('red', 'black', 'green')
cmap = c.test_colormap(mycmap)

image

More than 3 colors

Hello, just found this package, great work!,
I wonder... is it possible to make a colormap with more than 3 colors using the package functionality?,
Cheers,
Lucas.

impor pbl on some systems

looks like this code in version 0.9.5 is causing trouble on some systems (python 2.7.3)

     36 c = Colormap()
---> 37 colormap_names = c.colormaps + c.diverging_black
     38 # create an alias to test_colormap methiod
     39 test_colormap = c.test_colormap
http://www.bioconductor.org/packages/release/bioc/html/MEIGOR.html

Required module easydev not installed through pip

$ pip install colormap
$ python3
>>> import colormap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bers/.local/lib/python3.8/site-packages/colormap/__init__.py", line 31, in <module>
    from . import colors
  File "/home/bers/.local/lib/python3.8/site-packages/colormap/colors.py", line 26, in <module>
    from easydev.tools import check_param_in_list, swapdict, check_range
ModuleNotFoundError: No module named 'easydev'

"TypeError: string indices must be integers" when using predefined colormaps

Hello. I have this code:

from colormap import Colormap
c = Colormap()
mycmap = c.cmap('YlGnBu')

When I run that, I get the following error on the last line:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/akronix/.pyenv/versions/wikichron/lib/python3.6/site-packages/colormap/colors.py", line 860, in cmap
    index = np.linspace(0, 1, len(colors['red']))
TypeError: string indices must be integers

However, it does work if I create a colormap with key RGB values:

from colormap import Colormap
c = Colormap() 
mycmap = c.cmap( {'red':[1,1,0], 'green':[0,1,.39], 'blue':[0,1,0]}) 

The versions I'm using of the related packages are:

colormap==1.0.2
numpy==1.17.2

Any idea how to fix it or why I'm getting this error while other people are not?

Interaction issue between GDSCTools, Reports and Colormap

I've got an issue when running the test suite of GDSCTools. There are many ways to fix it, but I think the most natural fix is in the colormap package, hence this issue. Feel free to move it to one of the other repos if you think that's more appropriate.

The fix I'm proposing is that the cmap_builder-function should check if there is only one parameter given and it is already a matplotlib cmap, it should simply return that cmap.

A solution would look roughly like this:

from matplotlib.colors import Colormap as MPLColormap
...
def cmap_builder(name, name2=None, name3=None):
    ...
    elif name in c.colormaps:
        return c.cmap(name)
    elif isinstance(name, MPLColormap):   # Proposed addition
        return name                                     

This issue arises from the following code:
In GDCTools.anova_results:

class ANOVAResults(object):
    ....
    def get_html_table(...):
        ....
        cmap_clip = cmap_builder('#ffffff', '#0070FF')
        ...
        html.add_bgcolor(this, cmap_clip, mode='clip', threshold=clip_threshold)

The add_bgcolor comes from reports.HTMLTable class:

    def add_bgcolor(self, colname, cmap='copper', mode='absmax', threshold=2):
        ....
        cmap = cmap_builder(cmap)

So this last cmap_builder gets called with an object that's already a matplotlib colormap.

If you're happy with the above solution, I can submit a PR. If you want to fix it in Reports or GDSCTools, please let me know.

hex2dec is weird

The documentation states that hex2dec should take an integer as a parameter, but it actually takes a string with a hex-based number and then outputs a float in the [0-65536] range.

I also noticed that this is the only function that has "dec" in the name. Isn't this a universal operation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.