Sarmate.net Sarmate.net
Home Features Pricing Documentation Contact
Log in Sign up
Back to gallery
TikZ DE

Dirichlet-Funktion

Sarmate sarmate_examples 2026-05-03 0 17

Visualisierung der Dirichlet-Funktion, des klassischen Beispiels einer überall unstetigen Funktion in der Reellen Analysis. Aus der technischen TikZ-Galerie von Sarmate (Quellen: MartinThoma/LaTeX-examples unter MIT, TeXample.net unter LPPL) — siehe auch unsere 900+ Figuren auf /tikz-gallery.php.

Open in demo Sign in to like
\documentclass[12pt,border=5pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{calc,angles,quotes,positioning,decorations.markings,arrows.meta,patterns,intersections,shapes,trees}
\usepackage{amsmath,amssymb}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis lines=middle,
        width=15cm, height=15cm,     % size of the image
        grid = both,
        grid style={dashed, gray!30},
        enlargelimits=true,
        xmin=-1,     % start the diagram at this x-coordinate
        xmax= 1,     % end   the diagram at this x-coordinate
        ymin= 0,     % start the diagram at this y-coordinate
        ymax= 1,     % end   the diagram at this y-coordinate
        /pgfplots/xtick={-1,-0.8,...,1}, % make steps of length 0.2
        /pgfplots/ytick={0,0.1,...,1},   % make steps of length 0.1
        axis background/.style={fill=white},
        ylabel=y,
        xlabel=x,]
      \addplot[domain=-1:1, ultra thick,samples=100,blue]  {1};
      \label{plot one}
      \addplot[domain=-1:1, ultra thick,samples=100,red] {0};
      \label{plot two}
      \node [draw,fill=white] at (rel axis cs: 0.8,0.8) {\shortstack[l]{
      $f(x) =
    \left\lbrace\begin{array}{@{}l@{}l@{}l@{}}
       \tikz[baseline=-0.5ex]\node{\ref{plot one}}; \phantom{1cm}& 1 &  \text{ if } x \in \mathbb{Q}\\
       \tikz[baseline=-0.5ex]\node{\ref{plot two}}; & 0 & \text{ if } x \in \mathbb{R} \setminus \mathbb{Q}
    \end{array}\right.
$}};
    \end{axis}
\end{tikzpicture}
\end{document}
This example is licensed under CC‑BY‑4.0. You may copy, modify, and redistribute it as long as you credit the author (Sarmate sarmate_examples).