LaTeX forum ⇒ Graphics, Figures & TablesPgfplots line gradient

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

Pgfplots line gradient

Postby Molibdeno » Sat May 13, 2017 10:57 am

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

  1. \documentclass[11pt]{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage{textcomp}
  4. \usepackage[italian]{babel}
  5. \usepackage[
  6. a4paper,
  7. margin=15mm,
  8. bindingoffset=2mm,
  9. heightrounded,
  10. ]{geometry}
  11. \usepackage{amssymb}
  12. \usepackage{amsmath}
  13. \usepackage{mathtools}
  14. \usepackage{float}
  15. \usepackage{pgfplots}
  16. \usepackage{xcolor}
  17. \usepgfplotslibrary{external}
  18. \tikzexternalize
  19. \definecolor{gold}{HTML}{FFBF18}
  20. \pgfplotsset{width=7cm,compat=1.14}
  21. \pgfplotsset{
  22. colormap={redyellow}{rgb255(0cm)=(255,0,0); rgb255(1cm)=(255,255,0)}
  23. }
  24.  
  25. \begin{document}
  26.  
  27. \begin{tikzpicture}
  28. \begin{axis}[
  29. width=12cm,
  30. xmin=0, xmax=21,
  31. ymin=0, ymax=14,
  32. xlabel=ml,
  33. ylabel=pH,
  34. xmajorgrids=true,
  35. ymajorgrids=true,
  36. grid style=dashed,
  37. ytick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14},
  38. xtick={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
  39. ]
  40. \addplot[mark=none,ultra thick,
  41. mesh, % Use line segments instead of one unbroken line
  42. colormap={}{ % Define the colormap
  43. [1cm] color(0cm)=(red) color(1cm)=(gold)
  44. },
  45. ]
  46. coordinates {
  47. (1,3.61)(2,3.99)(3,4.16)(4,4.33)
  48. (5,4.52)(6,4.64)(7,4.80)(8,4.91)(9,5.06)
  49. (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)
  50. (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)
  51. (14,11.58)(14.5,11.78)(15,11.83)(15.5,11.91)
  52. (16,11.97)(17,12.08)(18,12.13)(19,12.18)(20,12.22)
  53. };
  54. \end{axis}
  55. \end{tikzpicture}
  56. \end{document}

Image

Thanks in advance

Tags:

User avatar
Stefan Kottwitz
Site Admin
Posts: 8537
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Sun May 14, 2017 11:07 am

Hi,

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

Stefan
Site admin


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 7 guests