Featured Book

LaTeX Beginners Guide

Who is online

In total there are 5 users online :: 2 registered, 0 hidden and 3 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: billboll, Google [Bot] and 3 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

Aperiodic Grid Topic is solved

TikZAdd tags Information and discussion about graphics, figures & tables in LaTeX documents.

Aperiodic Grid

Postby thomgraf on Fri May 17th, 2013

Hello,

Does anybody have an idea of how to create an aperiodic grid in the tikzpicture environment? Below is my example where I would like to have distances for the grid line of 5 horizontally and 2 vertically.

Code: Select all  •  Open in writeLaTeX
\begin{tikzpicture}[domain=1:9,x=0.4cm,y=0.5cm] % Zeichenbereich
  \draw [color=gray!50,dashed]  [step=2] (0,0) grid (20,12);
  \draw[very thick, -] (0,0) -- (20,0);
  \draw[very thick, -] (0,0) -- (0,12);
  \draw[very thick, -] (0,12) -- (20,12);
  \draw[very thick, -] (20,0) -- (20,12);
  \foreach \x in {0,5,...,20} \draw (\x,0) -- (\x,-0.4) node[below] {\x};
  \foreach \y in {0,2,...,12} \draw (0,\y) -- (-0.5,\y) node[left] {\y
};
%  \draw[very thick, color=red] plot[smooth] (\x,{(10)/(1+exp(-0.9*(\x-8)))});
  \draw[thick, color=blue, fill=blue] plot[mark=*, mark options={scale=1.3}] (2,2);
\end{tikzpicture
}

The step=2 option create a periodic grid with equal distances horizontally and vertically.

Thanks
Last edited by cgnieder on Fri May 17th, 2013, edited 1 time in total.
thomgraf
 
Posts: 8
Joined: Wed Jul 18th, 2012

Re: Aperiodic Grid  Topic is solved

Postby feuersaenger on Sat May 18th, 2013

Hi,

TikZ offsers the options xstep and ystep when using its grid instruction:

Code: Select all  •  Open in writeLaTeX
\tikz \draw (0,0) grid [xstep=.5,ystep=.75] (3,2);


However, your example looks as if you'd like to visualize some (data) plot.

You might be interested in the package pgfplots: it is based on tikz (and offers all of tikz's style options) but it simplifies the generation of plots and suitable axes considerably.

Here is an extract of its meta data:

PGFPlots draws high quality function plots in normal or logarithmic scaling with a user-friendly interface directly in TeX. The user supplies axis labels, legend entries and the plot coordinates for one or more plots and PGFPlots applies axis scaling, computes any logarithms and axis ticks and draws the plots. It supports line plots, scatter plots, piecewise constant plots, bar plots, area plots, mesh-- and surface plots, patch plots, contour plots, quiver plots, histogram plots, polar axes, ternary diagrams, smith charts and some more.

Your example would look as follows:

Code: Select all  •  Open in writeLaTeX
\documentclass[a4paper]{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.7}

\begin{document}
\thispagestyle{empty}

    \begin{tikzpicture
}[domain=1:9,x=0.4cm,y=0.5cm] % Zeichenbereich
    \draw [color=gray!50,dashed]  [step=2] (0,0) grid (20,12);
    \draw[very thick, -] (0,0) -- (20,0);
    \draw[very thick, -] (0,0) -- (0,12);
    \draw[very thick, -] (0,12) -- (20,12);
    \draw[very thick, -] (20,0) -- (20,12);
    \foreach \x in {0,5,...,20} \draw (\x,0) -- (\x,-0.4) node[below] {\x};
    \foreach \y in {0,2,...,12} \draw (0,\y) -- (-0.5,\y) node[left] {\y
};
%    \draw[very thick, color=red] plot[smooth] (\x,{(10)/(1+exp(-0.9*(\x-8)))});
    \draw[thick, color=blue, fill=blue] plot[mark=*, mark options={scale=1.3}] (2,2);
    \end{tikzpicture}

\begin{tikzpicture}
  \begin{axis}[
    xmin=0,
    xmax=20,
    ymin=0,
    ymax=12,
    grid=major,
    xlabel=$x$ Achse,
    ylabel=$y$ Achse,
    legend entries={Scatter},
 
]
    \addplot coordinates {(2,2)};
  \end{axis}
\end{tikzpicture}
\end{document
}


P.png
P.png (23.32 KiB) Viewed 888 times


Note that the default configuration of PGFPlots results in the same tick marks as your manually tuned example. It also offers the same markers as your selection (otherwise we could have configured them using an option list \addplot[<options>]). I have also added axis labels and a legend, just to demonstrate the idea.

PGFPlots also allows to reconfigure the appearance of an axis (like dashed grid lines or outer tick marks as in your example). Perhaps a brief look into the example of the pgfplots manual helps to decide if the package suits your needs.

Disclaimer note: I am author of PGFPlots.
Last edited by feuersaenger on Sun May 19th, 2013, edited 1 time in total.
feuersaenger
 
Posts: 33
Joined: Sun Oct 16th, 2011
Location: Rheinbach

Re: Aperiodic Grid

Postby cgnieder on Sat May 18th, 2013

Hi Christian, hi thomgraf

I really appreciate such a comprehensive answer but we are an English forum and I think it is unfair to our other users when we have German threads. So it would be really nice if you both could provide English versions of your posts.

By the way: there are also German LaTeX forums:

Regards
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen
System: TeXlive 2013, OpenSUSE 12.3
User avatar
cgnieder
Site Moderator
 
Posts: 1696
Joined: Sat Apr 16th, 2011
Location: Germany

Re: Aperiodic Grid

Postby thomgraf on Tue May 21st, 2013

Hi:

The following line did the job for me:
Code: Select all  •  Open in writeLaTeX
\draw[color=gray!50,dashed] (0,0) grid[xstep=5,ystep=2] (20,12);

Simply replace step by xstep and ystep.

Sorry for previously having posted in German.
Last edited by cgnieder on Tue May 21st, 2013, edited 1 time in total.
thomgraf
 
Posts: 8
Joined: Wed Jul 18th, 2012

Re: Aperiodic Grid

Postby localghost on Sun May 26th, 2013

thomgraf wrote:[…] Sorry for previously having posted in German.

Since you seem either not to be willing or be able to translate your question in defiance of the moderator request, I did that. m(
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses
User avatar
localghost
Site Moderator
 
Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany


Topic Tags

TikZ

Return to Graphics, Figures & Tables

Who is online

Users browsing this forum: billboll, Google [Bot] and 3 guests