Graphics, Figures & Tablespgfplots | Changing the Color Maps

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
niles
Posts: 92
Joined: Mon Dec 01, 2008 9:35 pm

pgfplots | Changing the Color Maps

Post by niles »

Hi

I am using pgfplots to make a plot, here is a MWE from the manual:

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm,amssymb}

\usepackage{pgfplots}
\usepgfplotslibrary{colormaps,external}
\tikzexternalize[shell escape=-enable-write18] %needed for the MiKTeX compiler

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      grid=major,
      colormap/blackwhite
    ]
      \addplot3[surf,samples=30,domain=0:1]{5*x*sin(2*deg(x))*y};
    \end{axis}
  \end{tikzpicture}
\end{document}
I am using the "blackwhite" color map. However as the output shows, the lowest values are black while the largest values are white. To me this is very "offensive" to the eye, but I still like the "neutral" look of black/white/grey. Is there a way to change the color map such that lowest values become grey instead of black?


Best,
Niles.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

pgfplots | Changing the Color Maps

Post by josephwright »

Taking a look in the documentation, the blackwhite map has a handy pair of start and end densities we can alter.

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm,amssymb}

\usepackage{pgfplots}
\usepgfplotslibrary{colormaps,external}
%\tikzexternalize[shell escape=-enable-write18] %needed for the MiKTeX compiler

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      grid=major,
      colormap={blackwhite}{gray(0cm)=(1); gray(1cm)=(0)} % Change here
    ]
      \addplot3[surf,samples=30,domain=0:1]{5*x*sin(2*deg(x))*y};
    \end{axis}
  \end{tikzpicture}
\end{document}
(BTW, MiKTeX should recognise --shell-escape as well as --enable-write18.)
Joseph Wright
niles
Posts: 92
Joined: Mon Dec 01, 2008 9:35 pm

Re: pgfplots | Changing the Color Maps

Post by niles »

Thanks, that is kind of you.

Best,
Niles.
Post Reply