pgfplots: Patchdiagramm, Farbe der einzelnen Rechtecke ändern

Nov 19 2020

Update: Folgefrage hier .


  • Ich möchte ein "Patchwork" -Diagramm mit erstellen pgfplots.
  • Ich benutze patch plots, siehe "Kapitel 4.6.13 Patch Plots".
  • Ich habe keine Erfahrung mit 3D-Plots (Surfen, Mesh usw.).
  • Frage: Ich möchte ein Rechteck mit einer benutzerdefinierten Farbe zuweisen. Ist das möglich?
  • Wie kann ich alternativ die Farbe ( point meta) beeinflussen, wenn ich sie coordinateswie in der MWE verwende?

Hintergrund: Ich möchte größeren Rechtecken eine "wichtigere" Farbe geben als kleinen Rechtecken, ähnlich (nicht gleich) wie bei der Visualisierung von https://windirstat.net/ oder http://kdirstat.sourceforge.net/(siehe Screenshot ).


\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    title = Just a Title,
    xmin = 0,
    xmax = 100,
    colormap/blackwhite, % Just for testing
]
\addplot [
    patch,
    patch type = rectangle,
    ] coordinates {
        (0,0) (30,0) (30,12) (0,12)
        (0,12) (30,12) (30,18) (0,18)
        (30,0) (50,0) (50,12) (30,12)
        (30,12) (50,12) (50,18) (30,18)
    };
\end{axis}
\end{tikzpicture}

\end{document}

Antworten

1 Noname Nov 20 2020 at 03:42

Sie könnten die patchplotsBibliothek benutzen . Dies ist mehr oder weniger das Beispiel von p. 472 an Ihren Anwendungsfall angepasst.

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\pgfplotsset{compat=1.17}
\begin{document}

\begin{tikzpicture}
\begin{axis}[view={0}{90},
    title = Just a Title]
\addplot [table/row sep=\\,
    patch,
    patch type=polygon,
    vertex count=4,
    patch table with point meta={
            % pt1 pt2 pt3 pt4 cdata
            0 1 2 3 2\\
            2 3 5 4 1.5\\
            1 6 7 2 3\\
            2 7 8 4 4\\},
    ] table {
        x y z\\
        0 0 0\\%0
        30 0 0\\%1
        30 12 0\\%2
        0 12 0\\%3
        30 18 0\\%4
        0 18 0\\%5
        50 0 0\\%6
        50 12 0\\%7
        50 18 0\\%8
    };
\end{axis}
\end{tikzpicture}
\end{document}

Oben wird auf die Farben über die Standardfarbkarte zugegriffen hot. Sie können Ihre eigenen definieren, damit Sie wissen, um welche Farbe es sich handelt.

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\pgfplotsset{compat=1.17}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
    title = Just a Title]
\addplot [table/row sep=\\,
    patch,
    patch type=polygon,
    vertex count=4,
    colormap={custom}{
        color(1)=(blue)
        color(2)=(green)
        color(3)=(orange)
        color(4)=(red)
    },
    patch table with point meta={
            % pt1 pt2 pt3 pt4 cdata
            0 1 2 3 1\\
            2 3 5 4 2\\
            1 6 7 2 3\\
            2 7 8 4 4\\},
    ] table {
        x y\\
        0 0\\%0
        30 0\\%1
        30 12\\%2
        0 12\\%3
        30 18\\%4
        0 18\\%5
        50 0\\%6
        50 12\\%7
        50 18\\%8
    };
\end{axis}
\end{tikzpicture}
\end{document}