lavavu / LavaVu

Lightweight, Automatable Visualisation & Analysis Viewing Utility
Other
53 stars 12 forks source link

Adding more Default colourmaps #54

Closed arijitlaik closed 6 years ago

arijitlaik commented 6 years ago

Can we have perceptually uniform colormaps, like viridis, plasma magma, colorcet or even perceptually-uniform colour maps by Fabio Crameri's Colour Map Suit, if possible i can send in a PR

OKaluza commented 6 years ago

Hi Arijit, the original default colourmaps ("diverge", "isolum" and "isorainbow") plus some of the newer additions ("cubelaw", "cubelaw2", "smoothheat", "coolwarm", "spectral") are designed to be perceptually uniform (diverging or linearly increasing intensity).

I'm always happy to add some more options to the defaults so look at the suggestions you linked. It looks like there are now a lot more tools available for generating and plotting perceptual uniformity, so I'd also like to add a function to take a list of simple colours and turn that into a perceptually uniform map.

arijitlaik commented 6 years ago

@OKaluza thanks, i am aware of the default perceptually uniform, I have stuff ready as text codes for viridis, and if you look at, Fabio Crameri's Colour Map Suit, his colour maps have python code,as well as text or csv, if you are busy i could send in a PR by the weekend

OKaluza commented 6 years ago

I looked at Fabio Crameri's maps, and while I like them, he has required attribution for every use. This is difficult to include in a package as all documentation will have to note this requirement whenever colourmap features are mentioned to notify users that they need to attribute him for the colourmaps they have used.
The matplotlib maps are easier to include as I can just attribute them in the code but users will not have to.

arijitlaik commented 6 years ago

Fine, then, will wait for the matplotlib colourmaps, thanks :)

OKaluza commented 6 years ago

92da514b3b1da227aa3d0c2a753503c61349caa9 I decided not to build in any new defaults into the library as there are attribution and copyright issues. Instead matplotlib colourmaps are now supported directly if matplotlib is installed.

import lavavu
lv = lavavu.Viewer()
cbar = lv.colourbar()

#Use a matplotlib preset
cbar.colourmap('viridis')
lv.display()

#Import an external map from Fabio Crameri's Colour Map Suit (eg: bilbao.py)
import bilbao
cbar.colourmap(bilbao.cm_data)
lv.display()

#Import an external map from colorcet
import colorcet
cbar.colourmap(colorcet.fire)
lv.display()
arijitlaik commented 6 years ago

Great. Thanks, closing the issue

arijitlaik commented 6 years ago

@OKaluza how would i get it working in a glucifer figure

figSr = glucifer.Figure(
    figsize=figSize,
    quality=3,
    title="Strain Rate Field 1.0/seconds",
    boundingBox=((GEO.nd(Model.minCoord[0]), GEO.nd(Model.minCoord[1])),
                 (GEO.nd(Model.maxCoord[0]), GEO.nd(Model.maxCoord[1]))))
#

figSr.Points(
    Model.swarm,
    Model._strainRate_2ndInvariant * GEO.Dimensionalize(
        1.0, 1. / u.seconds).magnitude,
    logScale=True,
    figsize=figSize,
    colours='viridis',
    valueRange=[1e-21, 1e-13],
    fn_mask=Model.materialField > stickyAirLayer.index,
    fn_size=fnSize)

??

OKaluza commented 6 years ago

You should be able to call the lavavu.matplotlib_colourmap function, but it's not possible in the current release because Underworld comes with an older stable release of LavaVu.

The latest changes to the development branch of Underworld should allow this as lavavu is now an external module rather than built in, and you can install your own version, eg: use the latest package on pip or one built from source.

fig = glucifer.Figure ()
fig.Points( ..., colours=lavavu.matplotlib_colourmap("plasma"))
fig.show()

I've found some bugs though and am in the process of making fixes, will let you know when the changes are committed.

arijitlaik commented 6 years ago

UPDATE: Things are working.

Thanks, I have the developement branch build and lavavu too, i had done something on the lines of

....
fig.Points( ..., colours=cbar.colourmap(bilbao.cm_data)

it was before you did some changes to the glucifer module