Ich würde gerne die Ladegradabhängigkeit verschiedener Linien farbig darstellen. Dazu habe ich bisher die Funktion opacity genutzt. Leider ist der Farbverlauf nicht eindeutig genug. Gibt es eine Möglichkeit den Farbverlauf nicht über ein Abschwächen der Farbe, sondern als Farbverlauf hin zu einer anderen Farbe zu realisieren? Beispielsweise von grün zu grau? So wie hier: alt text Die Darstellung der Legende gefällt mir ebenfalls sehr gut. Wie stelle ich diese so dar, dass die ausgefüllten Rechtecke ähnlich groß sind. Dies wäre sehr nützlich, um die Farbe genau erkennen zu können.

Öffne in Overleaf
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{siunitx}
\begin{document}

\begin{figure}
\centering 
\begin{tikzpicture}
\begin{axis}[%
domain=-14:0,
scale=0.85,
width=0.95\linewidth,
height=9cm,
scale only axis,
separate axis lines,
every outer x axis line/.append style={black},
every x tick label/.append style={font=\color{black}\footnotesize},
every y tick label/.append style={font=\color{black}\footnotesize},
xmin=-14,
xmax=0,
ymin=2.5,
ymax=4.2,
xlabel={Strom in $\SI{}{\ampere}$},
ylabel={Spannung in $\SI{}{\volt}$},
ylabel near ticks,
xlabel near ticks,
axis background/.style={fill=white},
scaled ticks=false,
y tick label style={/pgf/number format/.cd,use comma,fixed,precision=3},
legend style={at={(1,0)},anchor=south east}
]
\addlegendimage{white,fill=red,area legend}
\addlegendimage{white,fill=red,opacity=0.9,area legend}
\addlegendimage{white,fill=red,opacity=0.7,area legend}
\addlegendimage{white,fill=red,opacity=0.5,area legend}
\addlegendimage{white,fill=red,opacity=0.3,area legend}
\addlegendimage{white,fill=red,opacity=0.1,area legend}
\addplot+[mark=none, very thick, red] {0.0140*x + 4.18};
\addlegendentry{$\SI{100}{\percent}$}
\addplot+[mark=none, very thick, red, opacity=0.9] {0.0142*x + 4.01};
\addlegendentry{$\SI{90}{\percent}$}
\addplot+[mark=none, very thick, red, opacity=0.7] {0.0146*x + 3.9};
\addlegendentry{$\SI{70}{\percent}$}
\addplot+[mark=none, very thick, red, opacity=0.5] {0.0144*x + 3.7};
\addlegendentry{$\SI{50}{\percent}$}
\addplot+[mark=none, very thick, red, opacity=0.3] {0.014*x + 3.6};
\addlegendentry{$\SI{30}{\percent}$}
\addplot+[mark=none, very thick, solid, red,, opacity=0.1] {0.015*x + 3.4};
\addlegendentry{$\SI{10}{\percent}$}
\end{axis}
\end{tikzpicture}
\label{fig:Test}
\end{figure} 
\end{document}

gefragt 20 Apr '17, 14:58

Tobolf's gravatar image

Tobolf
69711
Akzeptiert-Rate: 0%

bearbeitet 20 Apr '17, 18:10

(20 Apr '17, 16:50) saputello

Ein "Farbverlauf" lässt sich am Besten durch eine colormap in pgfplots abbilden. Davon gibt es eine ganze Reihe, sie werden normalerweise für surface plots oder andere, kontinuierlich gefärbte Plots verwendet.

Man kann colormap fuer normale Linienplots auch verwenden -- allerdings muss man dafür die Farbe eine colormap in die jeweiligen Optionen des \addplot Befehls reinbekommen. Eine sinnvolle Methode dafür ist ein relativ junges Feature in pgfplots: cycle list={[of colormap]}, von der es eine Reihe von Varianten gibt (wie samples of colormap={<anzahl> of <colormap name>} oder colors of colormap={0,10,50,100 of <colormap name>} oder indices of colormap={0,1,2,3,10 of <colormap name>}).

Angewandt auf Dein Beispiel könnte das wie folgt aussehen (wobei ich alles außer den eigentlichen Farbverläufen ausgeblendet habe):

Öffne in Overleaf
\documentclass{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.14}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
domain=-14:0,
xmin=-14,
xmax=0,
ymin=2.5,
ymax=4.2,
scaled ticks=false,
legend style={at={(1,0)},anchor=south east},
legend entries={100\%, 90\%, 70\%, 50\%, 30\%, 10\%},
legend image code/.code={
    \fill [#1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
},
cycle list={[samples of colormap={6 of viridis}]},
]
\addplot {0.0140*x + 4.18};
\addplot {0.0142*x + 4.01};
\addplot {0.0146*x + 3.9};
\addplot {0.0144*x + 3.7};
\addplot {0.014*x + 3.6};
\addplot {0.015*x + 3.4};
\end{axis}
\end{tikzpicture}

\end{document}

Beispiel mit viridis colormap

pgfplots kommt mit einem ganzen Zoo von colormaps, von denen die oben genutzte viridis eine der default colormaps ist. Die Bibliothek colorbrewer kommt mit einer Reihe weiterer nützlicher colormaps. Hier ist beispielsweise die colormap/OrRd-6 aus dieser Bibliothek, wobei ich die Reihenfolge mit indices of colormap umgedreht habe:

Öffne in Overleaf
\usepgfplotslibrary{colorbrewer}

..

\begin{axis}[...
  colormap/OrRd-6,
  cycle list={[indices of colormap={6,5,4,3,2,1 of OrRd-6}]},
]

Beispiel mit colormap/OrRd-6

Permanenter link

beantwortet 01 Mai '17, 00:20

cfeuersaenger's gravatar image

cfeuersaenger
3.7k23
Akzeptiert-Rate: 34%

bearbeitet 02 Mai '17, 10:35

saputello's gravatar image

saputello
11.1k154365

Hier ist mal noch eine Alternative, bei der eine Farbserie mit 100 Schritten definiert wird und die Legende unabhängig von den Plots in einer Schleife erstellt wird.

Öffne in Overleaf
\documentclass[margin=5pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}% lädt auch tikz
\pgfplotsset{compat=1.14}

% Farbserie mit 100 Schritten definieren
\definecolorseries{plotcolor}{rgb}{last}{yellow}{blue}
\resetcolorseries[100]{plotcolor}

% Eigener Legendenstil
\pgfplotsset{
  my area legend/.style={
    draw=none,
    inner ysep=0pt,
    inner xsep=3pt,
    row sep=-.5\pgflinewidth,
    nodes={inner ysep=0pt},
    legend image code/.code={%
      \filldraw[#1,draw=none] (0cm,-0.08cm) rectangle (0.4cm,0.08cm);
    }
  },
  myplotcolor/.style={plotcolor!![#1]}
}

\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[%
    domain=-14:0,
    scale=0.85,
    width=0.95\linewidth,
    height=9cm,
    scale only axis,
    separate axis lines,
    every outer x axis line/.append style={black},
    every x tick label/.append style={font=\color{black}\footnotesize},
    every y tick label/.append style={font=\color{black}\footnotesize},
    xmin=-14,
    xmax=0,
    ymin=2.5,
    ymax=4.2,
    xlabel={Strom in $\si{\ampere}$},
    ylabel={Spannung in $\si{\volt}$},
    axis background/.style={fill=white},
    scaled ticks=false,
    y tick label style={/pgf/number format/.cd,use comma,fixed,precision=3},
    legend style={
      at={(1,0)},yshift=5pt,xshift=-1em,anchor=south east,
      my area legend,
      name=legend
    },
    every axis plot/.style={no markers,very thick,solid}
  ]
    % Legende
    \pgfplotsinvokeforeach {100,90,...,10}{
      \addlegendimage{myplotcolor=#1,my area legend}
      \addlegendentry{}
    }
    %Plots
    \addplot[myplotcolor=100] {0.0140*x + 4.18};
    \addplot[myplotcolor=90] {0.0142*x + 4.01};
    \addplot[myplotcolor=70] {0.0146*x + 3.9};
    \addplot[myplotcolor=50] {0.0144*x + 3.7};
    \addplot[myplotcolor=30] {0.014*x + 3.6};
    \addplot[myplotcolor=10] {0.015*x + 3.4};
  \end{axis}
  % Beschriftung der Legende
  \path[nodes={font=\tiny,inner xsep=0pt}]
    (legend.north west) node [anchor= east] {$100$}
    (legend.west) node [anchor= east] {$50$}
    (legend.south west) node [anchor= east] {$0$}
    (legend.north) node [anchor=south] {Par\,[$\si{\percent}$]}
  ;
\end{tikzpicture}
\end{document}

alt text

Permanenter link

beantwortet 21 Apr '17, 14:01

esdd's gravatar image

esdd
17.7k254256
Akzeptiert-Rate: 62%

Hier ein Übergang von blau nach rot.

Öffne in Overleaf
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usepackage{siunitx}
\begin{document}

\begin{figure}
  \centering 
  \begin{tikzpicture}
    \begin{axis}[%
      domain=-14:0,
      scale=0.85,
      width=0.95\linewidth,
      height=9cm,
      scale only axis,
      separate axis lines,
      every outer x axis line/.append style={black},
      every x tick label/.append style={font=\color{black}\footnotesize},
      every y tick label/.append style={font=\color{black}\footnotesize},
      xmin=-14,
      xmax=0,
      ymin=2.5,
      ymax=4.2,
      xlabel={Strom in $\SI{}{\ampere}$},
      ylabel={Spannung in $\SI{}{\volt}$},
      ylabel near ticks,
      xlabel near ticks,
      axis background/.style={fill=white},
      scaled ticks=false,
      y tick label style={/pgf/number format/.cd,use comma,fixed,precision=3},
      legend style={at={(1,0)},anchor=south east},
      every axis plot/.style = {
        no markers, very thick, solid,
        legend image code/.code={
          \filldraw[#1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
        },
      }
      ]
      \addplot[red!0!blue] {0.0140*x + 4.18};
      \addlegendentry{$\SI{100}{\percent}$}
      \addplot[red!20!blue] {0.0142*x + 4.01};
      \addlegendentry{$\SI{90}{\percent}$}
      \addplot[red!40!blue] {0.0146*x + 3.9};
      \addlegendentry{$\SI{70}{\percent}$}
      \addplot[red!60!blue] {0.0144*x + 3.7};
      \addlegendentry{$\SI{50}{\percent}$}
      \addplot[red!80!blue] {0.014*x + 3.6};
      \addlegendentry{$\SI{30}{\percent}$}
      \addplot[red!100!blue] {0.015*x + 3.4};
      \addlegendentry{$\SI{10}{\percent}$}
    \end{axis}
  \end{tikzpicture}
  \label{fig:Test}
\end{figure} 
\end{document}

alt text

Permanenter link

beantwortet 21 Apr '17, 11:54

Henri's gravatar image

Henri
15.7k133943
Akzeptiert-Rate: 46%

Deine Antwort
Vorschau umschalten

Folgen dieser Frage

Per E-Mail:

Wenn sie sich anmelden, kommen Sie für alle Updates hier in Frage

Per RSS:

Antworten

Antworten und Kommentare

Markdown-Grundlagen

  • *kursiv* oder _kursiv_
  • **Fett** oder __Fett__
  • Link:[Text](http://url.com/ "Titel")
  • Bild?![alt Text](/path/img.jpg "Titel")
  • nummerierte Liste: 1. Foo 2. Bar
  • zum Hinzufügen ein Zeilenumbruchs fügen Sie einfach zwei Leerzeichen an die Stelle an der die neue Linie sein soll.
  • grundlegende HTML-Tags werden ebenfalls unterstützt

Frage-Themen:

×296
×2

gestellte Frage: 20 Apr '17, 14:58

Frage wurde gesehen: 9,926 Mal

zuletzt geändert: 01 Mai '17, 00:20