Graphics, Figures & TablesPgfplots line gradient

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Molibdeno
Posts: 12
Joined: Fri Apr 07, 2017 12:15 pm

Pgfplots line gradient

Post by Molibdeno »

How can I do so that the color gradient starts at pH values around 4 (~ 2 ml)?

Code: Select all

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage[italian]{babel}
\usepackage[
  a4paper,
  margin=15mm,
  bindingoffset=2mm,
  heightrounded,
]{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{float}
\usepackage{pgfplots}
\usepackage{xcolor}
\usepgfplotslibrary{external}
\tikzexternalize
\definecolor{gold}{HTML}{FFBF18}
\pgfplotsset{width=7cm,compat=1.14}
\pgfplotsset{
colormap={redyellow}{rgb255(0cm)=(255,0,0); rgb255(1cm)=(255,255,0)}
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
     width=12cm,
     xmin=0, xmax=21, 
     ymin=0, ymax=14,
     xlabel=ml,
     ylabel=pH,
     xmajorgrids=true,
     ymajorgrids=true,
    grid style=dashed,
    ytick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14},
    xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
    ]
    \addplot[mark=none,ultra thick, 
    mesh, % Use line segments instead of one unbroken line
        colormap={}{ % Define the colormap
           [1cm] color(0cm)=(red) color(1cm)=(gold)
        },
    ]
    coordinates {
    (1,3.61)(2,3.99)(3,4.16)(4,4.33)
    (5,4.52)(6,4.64)(7,4.80)(8,4.91)(9,5.06)
    (10,5.24)(10.5,5.38)(11,5.49)(11.5,5.67)(12,5.82)(12.2,5.99)(12.4,6.09)
    (12.6,6.46)(12.8,6.98)(13,7.35)(13.2,10.92)(13.4,11.22)(13.6,11.37)(13.8,11.50)
    (14,11.58)(14.5,11.78)(15,11.83)(15.5,11.91)
    (16,11.97)(17,12.08)(18,12.13)(19,12.18)(20,12.22)
    };
\end{axis}
\end{tikzpicture}
\end{document}
Image

Thanks in advance

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
TikZ book
User avatar
Stefan Kottwitz
Site Admin
Posts: 10314
Joined: Mon Mar 10, 2008 9:44 pm

Pgfplots line gradient

Post by Stefan Kottwitz »

Hi,

a simple idea would be: just split and make two plots in the same diagram, just one with the gradient.

Stefan
LaTeX.org admin
Post Reply