## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Aperiodic Grid Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
thomgraf
Posts: 9
Joined: Wed Jul 18, 2012 12:21 pm

### Aperiodic Grid

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.

\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 17, 2013 11:44 pm, edited 1 time in total.

feuersaenger
Posts: 34
Joined: Sun Oct 16, 2011 5:56 pm
Location: Rheinbach
Contact:
Hi,

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

\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:

\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 (23.32 KiB) Viewed 1847 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 19, 2013 3:15 pm, edited 1 time in total.

 Link: BBcode: Topic is solved[/url]" title="Click to select post's link in BBcode format" onclick="this.focus();this.select();" /> HTML: Topic is solved" title="Click to select post's link in HTML format" onclick="this.focus();this.select();" /> Hide post links

cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
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

thomgraf
Posts: 9
Joined: Wed Jul 18, 2012 12:21 pm
Hi:

The following line did the job for me:
\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 21, 2013 6:18 pm, edited 1 time in total.

localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany
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

¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses