Free color tool for figures

Color palette from image: extract the main colors of any figure

Drop in a chart, figure or photo, or paste one from the clipboard, and this color palette generator from image finds its main colors. Copy each one as HEX or RGB, see how much of the image it covers, check that the palette stays distinguishable with color blindness, and export it for matplotlib, ggplot2, CSS or JSON.

  • Free, no sign-up
  • Runs in your browser, nothing uploaded
  • HEX, RGB and share of each color
  • Code for matplotlib, ggplot2 and CSS

Drop a figure, chart or photo here, or

Or paste an image with Ctrl+V (Cmd+V on a Mac).

PNG, JPEG or WebP. The image is read in your browser and never uploaded.

Skips near-white and near-black pixels so the palette shows the figure's colors. Turn off for photos where white or black matter.

Your palette appears here

The main colors with HEX, RGB and their share of the image, ready to copy as code and checked for color blindness.

How to use it

Get a color palette from an image in three steps

Load a figure, read its main colors, then copy them as code and check them for color blindness. The image is analysed on this page and never uploaded.

  1. The empty tool: the image box, the number of colors and the switch that skips white and black
    1

    Drop in a figure

    Drop a PNG, JPEG or WebP on the box, choose a file, or paste one with Ctrl+V. Set the number of colors, and keep white and black skipped for figures.

  2. The six colors of the sample pie chart with HEX codes, RGB values and shares
    2

    Read the palette

    The main colors appear with HEX, RGB and their share of the image. Click a swatch to copy its HEX code, and order the colors by share, hue or lightness.

  3. The R ggplot2 export of the sample palette with its Copy button
    3

    Copy the colors as code

    Pick HEX list, CSS variables, matplotlib, ggplot2, MATLAB or JSON and press Copy. Below the code, the color vision check flags pairs that look alike with color blindness.

Six palettes taken from our own figures

Real runs of the tool on figures from this site, with the colors, shares and checks exactly as it reported them, white and black skipped.

Gene expression bar chart beside its four colors: teal, blue, red and light gray
A grouped bar chart at four colors: the bar fills come back as exact HEX codes, teal #1B99A3 (35%), blue #1E6CAD (30%) and red #EA6154 (27%), plus a light gray average #CCD0D1 (8.0%).
Color vision check for a UMAP plot palette with two flagged pairs
A single-cell UMAP plot at five colors, in the color vision check: the blue of population 1 (#1F5FCD) and the purple of population 3 (#7D2CCC) fall to ΔE 1.1 with deuteranopia, and teal and lavender gray to ΔE 8.9 with protanopia.
Immune profile heatmap beside its eight colors ordered from dark purple to pale yellow
A sequential heatmap at eight colors, ordered by lightness: deep purple #410888, purple #7E3BA3, pink #DA6593, two oranges #FBAF69 and #FBC474 and pale yellow #FBEEA9, with a small green #6B927F (1.8%) from the colored bars above the columns.
Healthy versus diseased tissue illustration beside its six pink and mauve colors
An illustration of healthy and diseased tissue at six colors: four pinks from #FAD2D1 to #CD636C make up 86% of the colored pixels, with mauve #B694A6 and dark gray #665D69. All six are averages, as expected for shaded artwork.
Cell division illustration beside its six colors ordered by hue, from salmon through blues to indigo
The five stages of cell division at six colors, ordered by hue: a small salmon #D7A69D (3.5%) from the orange spindle poles, then light blue #C0D2EE, blue #6173AE, periwinkle #A1ABD7, indigo #37377D and the palest blue #DAE9F8, the largest group at 39%.
Growth curve line chart beside its six colors, led by the pale band color
A line chart with shaded bands at six colors: the pale bands make the largest group (#EAEAF5, 63%), and the thin lines come out as averages such as #1552BC and #EC6359, since most of their pixels are blended edges.

Guide

How the palette is built, and how to use it

How the colors are found, why backgrounds are skipped, when you get exact HEX codes, the color blindness check, and how to paste the palette into your code.

How the colors are extracted

To extract a color palette from an image, the tool sorts similar pixels into groups and reports one color per group. It works on a copy of at most 250,000 pixels, sampled without blending so flat colors keep their exact values, and it measures color differences in OKLab, a perceptual color space published by Björn Ottosson in 2020 and now part of CSS Color Module Level 4.

  • Pixels are counted by exact color, then gathered into small bins 8 levels wide per channel, so large photos stay fast.
  • The starting points are chosen with k-means++ (Arthur and Vassilvitskii, 2007) from 8 fixed seeds, and the run with the lowest error wins, so the same image always gives the same palette.
  • k-means then moves each group center to the average of its pixels, again and again, until no pixel changes group.
  • Each color's share is the fraction of counted pixels in its group. The list is sorted by share unless you choose hue or lightness.

Pixels in OKLab, grouped by k-means

Across: OKLab a, green to red. Up: OKLab b, blue to yellow.

  • #54A6F633%
  • #56D06733%
  • #F8C02033%

90 pixels scattered around three chart colors, grouped by the same code the tool runs. Each group becomes one swatch.

Ignore white backgrounds and black text

Most figures are largely white page with black labels and axes. Counted as colors, they would fill the palette and push the data colors down to small shares. With Ignore white background and black text switched on, which is the default, the tool skips pixels that are very light with almost no color and pixels that are very dark, then measures the shares on what is left.

  • Near-neutral whites and light grays are skipped, including the light gray panel of a default ggplot2 plot. Pale tints such as a light pink or a pastel blue are kept.
  • Black and near-black are skipped. Dark grays such as #333333 are kept.
  • If an image is almost all white and black, the filter switches itself off, so you still get a palette.
  • Turn the switch off for photos, where white snow or a black background can be part of the palette.

Transparent PNGs

Transparent pixels are always skipped, so a chart exported with a transparent background gives the palette of its marks alone.

A bar chart on a white page

All pixels

  • #FFFFFF76%
  • #1F77B411%
  • #FF7F0E6.4%
  • #2CA02C3.7%
  • #0000003.3%

White and black ignored

  • #1F77B451%
  • #FF7F0E31%
  • #2CA02C18%

Shares measured by the tool on this small chart, with the switch off and on.

Exact HEX codes from charts, averages from photos

Charts drawn in matplotlib, ggplot2, Prism or Excel fill bars and slices with one flat color, but their edges are anti-aliased: a row of in-between pixels blends the fill into the background. An average over the group would drift toward those blends. So when one exact color holds at least a quarter of its group, the tool reports that color itself. In photos and gradients no single value dominates, and the tool reports the group average, marked avg.

  • Use PNG rather than JPEG for charts: JPEG compression shifts flat colors by a few levels.
  • Ask for more colors than the image has and the blended edge pixels form extra groups with small shares, which tells you they are minor.
  • Thin lines are mostly edge pixels, so a line color may come out as an average. Zoom in on the legend or a thick part of the plot for its exact value.

A thin line, enlarged

Average of the group#75BAFF
Reported#48A4FEThe most common value in the group

Most pixels of a thin line are blended with the white page, so the group average comes out lighter. The color that fills the line is reported instead.

Check the palette for color blindness

A palette taken from a photo or from another paper is not automatically readable by everyone. Under the swatches, the tool shows the colors as seen with deuteranopia and protanopia, the complete forms of red-green color vision deficiency, which is the most common kind, using the Machado et al. (2009) simulation at full severity. It flags any pair that is clearly different in normal vision but falls below a CIEDE2000 difference of 10 after simulation.

  • ggplot2's default colors for three groups, #F8766D, #00BA38 and #619CFF, are a typical case: the red and the green fall to a difference of about 6 with deuteranopia.
  • If a pair is flagged, change one of the two colors, or make sure the groups also differ by marker shape, line style or a direct label.
  • To see the whole figure rather than its palette, open it in the Colorblind Simulator.

ggplot2's default colors for three groups

Normal vision#F8766D#00BA38#619CFF
Deuteranopia#B6A86A#AC9C45#5A96FD
Protanopia#958D6C#BDA824#70A5FF

Red and green: ΔE 5.9 with deuteranopia

Machado et al. (2009) simulation at full severity; ΔE is the CIEDE2000 difference between the simulated colors.

Use the colors in matplotlib, ggplot2 and CSS

Pick an export format, copy it, and paste it into your code. The colors come out in the order shown, so sort them by share, hue or lightness first.

  • Python matplotlib: sets the default color cycle with cycler, so each new line or bar series takes the next color.
  • R ggplot2: a pal vector for scale_color_manual(values = pal). Use scale_fill_manual for bars and areas.
  • CSS variables: --palette-1, --palette-2 and so on, for web figures and slides built in HTML.
  • MATLAB, a plain HEX list, and JSON with each color's RGB values and share are there too.

Ordered groups

For groups with an order, such as doses or time points, sort by lightness so the colors step from dark to light.

The sample pie chart, exported

# Python · matplotlib

import matplotlib.pyplot as plt
from cycler import cycler

colors = ["#48A4FE", "#57CF62", "#FDBF1C", "#FE4546"]
plt.rcParams['axes.prop_cycle'] = cycler(color=colors)

# R · ggplot2

pal <- c("#48A4FE", "#57CF62", "#FDBF1C", "#FE4546")

# ggplot(df, aes(x, y, color = group)) + geom_point() +
scale_color_manual(values = pal)

Copy the format you need; the colors keep the order shown in the tool.

Frequently asked questions

Quick answers on extracting a palette, privacy, colors that differ slightly, how many colors to ask for, shares, and colorblind-safe palettes.

How do I get a color palette from an image?

Drop the image on the tool above, choose it from your files, or paste it with Ctrl+V (Cmd+V on a Mac). The main colors appear at once with HEX, RGB and their share of the image. Set the number of colors from 3 to 12, then copy a swatch or export the whole palette as code.

Is my image uploaded anywhere?

No. The image is decoded and analysed by JavaScript in your browser, and nothing is sent to a server. The same goes for the color blindness check and the code exports.

Why is a color slightly different from the one I used in my chart?

JPEG compression shifts flat colors by a few levels, so export charts as PNG. Thin lines are mostly blended edge pixels, so no single value dominates and you get an average, marked avg. Colors without that mark occur in the image exactly as shown.

How many colors should I extract?

Start with the number of groups in the figure plus one or two. For a chart with four series, try six: the four fills and room for grays or edge blends. If the palette shows near-duplicates with small shares, lower the number; if two distinct colors are merged into one, raise it.

What does the percentage next to each color mean?

It is the share of counted pixels in that color's group. With the background filter on, white and black pixels are left out first, so the shares describe the colored part of the figure. The bar above the swatches shows the same shares as widths.

Can I get a colorblind-safe palette from my image?

The tool tells you whether the extracted colors stay apart with deuteranopia and protanopia, but it does not change them. If a pair is flagged, swap one color of the pair for one from a tested set such as Okabe-Ito, listed with HEX codes on the colorblind friendly palette page.

How is this different from a color picker?

A color picker gives the value of the one pixel you click. This tool looks at every sampled pixel and sums the image up as a few representative colors with their shares, which is what you need to reuse the palette of a figure.

Use your palette in a new chart

Upload a CSV or Excel file to the bar chart generator and describe the colors you want, for example with the HEX codes from your palette.

Open the bar chart generator
A clustered correlation matrix beside its eight colors ordered by lightness, from dark gray and dark red to pale gray