Skip to content

Managing colormaps and palettes for Matplotlib, Gimp and Inkscape in python

Notifications You must be signed in to change notification settings

RollsW/Paint-Box

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Paint Box

GitHub release (latest by date including pre-releases) GitHub Code style: black

Python code for building matplotlib color palettes and exporting them for use in either Inkscape or Gimp.

The story so far

I was in the middle of some code with a lot of matplotlib figures. Changing the figure palette within matplotlib is reasonably straightforward, but then... I was putting them on a poster, and adding them to a presentation - both of these applications needed other graphics from other sources to make sense, and I suddenly realised that I had no way of making my figures match the rest of the colour scheme.

This simple bit of code takes an input of an arbitrary number of colours, either in rgb or hex format, and uses them to generate 1) a range of matplotlib colormaps and 2) a .gpl file (gimp palette) containing the original colours, as well as a range of saturation and brightness options.

Uses

Once you have set up the object, you can either use PaintBox.basemap as a standard matplotlib colormap, or export the whole thing as either an array of swatches (small picture files) or as a palette to use in your favorite open-source graphics editor.

Basic commands

palette = [ a list of colours] It's easiest to set this up first. We can handle hex "#ffffff", rgb as (0.x,0.x,0.x) or rgb as (255,255,255) or as the equivalent lists: i.e. [0.x,0.x,0.x] or [255,255,255]

x = PaintBox("name",palette) generates the paintbox object

x.palette_path = r".\test" for inkscape, use r"C:\Users\your_name\AppData\Roaming\inkscape\palettes"

x.swatch_location(r".\test") wherever we want the swatches saved

x.swatches(save=True) save swatches of the colour scheme to the swatch_location

x.export(x.palette_path) save a GPL palette to the palette_path

Good sources of colour schemes include:

Swatch examples

  • Base Map

    Base Map

  • Lighter

    Lighter

  • Much Lighter

    Much lighter

  • Darker

    Darker

  • Much Darker

    Much darker

  • Desaturated

    Desaturated

  • Very Desaturated

    Very Desaturated

  • Saturated

    Saturated

  • Very Saturated

    Very Saturated