Graphics, Figures & TablesCustomization of Plot

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
grumm
Posts: 2
Joined: Wed Jul 03, 2013 11:10 am

Customization of Plot

Post by grumm »

Hello,

here is an excerpt from my document:

Code: Select all

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}

\pgfplotsset{
  compat=1.3,
  width=12cm
}

\begin {document}
  \begin{tikzpicture}
    \begin{axis}[
      date coordinates in=x,
      xmin=2011-03-19,
      xmax=2013-06-30,
      xlabel={March 19th  2011 through June 2013},
      xticklabel=\day,
      ylabel={Weight},
    ]
      \addplot coordinates {
        (2011-03-19,191.0)
        (2011-03-20,191.2)
        (2011-03-21,192.4)
        (2011-03-22,193.2)
        (2011-03-23,192.6)
        (2011-03-25,192.4)
        (2011-03-26, 195.4)
        (2011-03-27, 194.6)
        (2011-03-28, 194.2)
        (2011-03-29, 193.8)
        (2011-03-30, 194.2)
        (2011-03-31, 194.6)
      };
    \end{axis}
  \end{tikzpicture}
\end{document}
Is it possible to do any of the following?
  1. assign a color to a single point?
  2. assign a shape to a single point?
  3. specify a particular date with xticklabel=\day, or some other way?
The full data set contains about a thousand values and I would like to be able to highlight individual points in the graph.

Thank you very much for any help,
Gerard McConnell
Last edited by localghost on Wed Jul 03, 2013 11:30 am, edited 1 time in total.

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Klausiber
Posts: 16
Joined: Sun Apr 14, 2013 11:41 pm

Customization of Plot

Post by Klausiber »

grumm wrote: Is it possible to do any of the following?
  1. assign a color to a single point?
  2. assign a shape to a single point?
  3. specify a particular date with xticklabel=\day, or some other way?
Just use individual addplot commands and overwrite the important points. You may also use ordinary TikZ (see pgf) drawing commands with the axis cs coordinate system:

Code: Select all

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}

\pgfplotsset{
  compat=1.3,
  width=12cm
}

\begin {document}
  \begin{tikzpicture}
    \begin{axis}[
      date coordinates in=x,
      xmin=2011-03-19,
      xmax=2011-03-31,
      xlabel={March 2011},
      xticklabel={\day.\month.},
      ylabel={Weight},
    ]
      \addplot[blue, mark=*] coordinates {
        (2011-03-19,191.0)
        (2011-03-20,191.2)
        (2011-03-21,192.4)
        (2011-03-22,193.2)
        (2011-03-23,192.6)
        (2011-03-25,192.4)
        (2011-03-26,195.4)
        (2011-03-27,194.6)
        (2011-03-28,194.2)
        (2011-03-29,193.8)
        (2011-03-30,194.2)
        (2011-03-31,194.6)
      };

      \addplot[only marks, red, mark=*, mark size=4pt] coordinates {
        (2011-03-23,192.6)
      };

      \node[coordinate, pin=below:{Important!}] at (axis cs:2011-03-23,192.6) {};

    \end{axis}
  \end{tikzpicture}
\end{document}
If you want to highlight a specific date you could use extra x ticks as explained here. For more information refer to the excellent pgfplots documentation.
grumm
Posts: 2
Joined: Wed Jul 03, 2013 11:10 am

Re: Customization of Plot

Post by grumm »

That is outstanding, thanks very much :-)
Post Reply