Graphics, Figures & Tablespgfplots | Plot Size and Axis Scale

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
eisegal
Posts: 10
Joined: Fri Nov 02, 2012 12:40 pm

pgfplots | Plot Size and Axis Scale

Post by eisegal »

Hello to all,

I've got a problem with the following example. I'd like to extend the width. how is this possible? (there is more data which is not included in this MWE.)

Furthermore, I try do manipulate the year dates. Which step is necessary so that it is shown as year dates?

greetings

Code: Select all

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{figure}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xmin=1934, xmax=2012,
ymin=0, ymax=600,
axis lines=center,
axis on top=true,
domain=0:1,
xlabel=Year,
ylabel=Number of failed banks]
\addplot[color=red,mark=x] coordinates {
(1988, 232)
(1989, 531)
(1990, 381)
(1991, 268)
(1992, 179)
(1993, 50)
(1994, 15)
(1995, 8)
(1996, 6)
(1997, 1)
(1998, 3)
(1999, 8)
(2000, 7)
(2001, 4)
(2002, 11)
(2003, 3)
(2004, 4)
(2005, 0)
(2006, 0)
(2007, 3)
(2008, 25)
(2009, 140)
(2010, 157)
(2011, 92)
(2012, 49)
};
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pgfplots | Plot Size and Axis Scale

Post by localghost »

eisegal wrote:[…] I'd like to extend the width. how is this possible? (there is more data which is not included in this MWE.) […]
For the width of the complete diagram you can explicitly set the width option for the axis environment (see code below). If you just want to shift the actual plot more towards the y axis, simply increase xmin.
eisegal wrote:[…] Furthermore, I try do manipulate the year dates. Which step is necessary so that it is shown as year dates?
Actually the years are shown. But by default there is a comma as thousands separator. So you need a special formatting for the numbers (see code below).

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      width=0.8\textwidth,
      height=0.6\textwidth,
      axis lines=center,
      axis on top=true,
      xmin=1934,
      xmax=2012,
      xlabel={Year},
      xticklabel style={/pgf/number format/1000 sep=},
      ymin=0,
      ymax=600,
      ylabel={Number of failed banks}
    ]
      \addplot[color=red,mark=x] coordinates {
        (1988,232)
        (1989,531)
        (1990,381)
        (1991,268)
        (1992,179)
        (1993,50)
        (1994,15)
        (1995,8)
        (1996,6)
        (1997,1)
        (1998,3)
        (1999,8)
        (2000,7)
        (2001,4)
        (2002,11)
        (2003,3)
        (2004,4)
        (2005,0)
        (2006,0)
        (2007,3)
        (2008,25)
        (2009,140)
        (2010,157)
        (2011,92)
        (2012,49)
      };
    \end{axis}
  \end{tikzpicture}
\end{document}

Further reading:

Thorsten
Attachments
wtmp.png
wtmp.png (5.52 KiB) Viewed 92503 times
eisegal
Posts: 10
Joined: Fri Nov 02, 2012 12:40 pm

Re: pgfplots | Plot Size and Axis Scale

Post by eisegal »

thank you very much! how is it possible to write the xaxis label on the right side (now its above the curve)?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pgfplots | Plot Size and Axis Scale

Post by localghost »

eisegal wrote:[…] how is it possible to write the xaxis label on the right side (now its above the curve)?
For such a kind of plot it is perhaps better to write the axes labels below and left in order to get them completely out of the plot area.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      width=0.8\textwidth,
      height=0.6\textwidth,
      axis x line=bottom,
      xmin=1934,
      xmax=2012,
      xlabel={Year},
      xlabel near ticks,
      xticklabel style={/pgf/number format/1000 sep=},
      axis y line=left,
      ymin=0,
      ymax=620,
      ylabel={Number of failed banks},
      ylabel near ticks
    ]
      \addplot[color=red,mark=x] coordinates {
        (1988,232)
        (1989,531)
        (1990,381)
        (1991,268)
        (1992,179)
        (1993,50)
        (1994,15)
        (1995,8)
        (1996,6)
        (1997,1)
        (1998,3)
        (1999,8)
        (2000,7)
        (2001,4)
        (2002,11)
        (2003,3)
        (2004,4)
        (2005,0)
        (2006,0)
        (2007,3)
        (2008,25)
        (2009,140)
        (2010,157)
        (2011,92)
        (2012,49)
      };
    \end{axis}
  \end{tikzpicture}
\end{document}
Attachments
wtmp.png
wtmp.png (5.69 KiB) Viewed 92487 times
eisegal
Posts: 10
Joined: Fri Nov 02, 2012 12:40 pm

Re: pgfplots | Plot Size and Axis Scale

Post by eisegal »

That's just perfect! Thank you!
Post Reply