Meine Frage schliesst sich der folgenden Frage an: Wie kann ich eine Positionierung von Balken in pgfplots erreichen.

Das folgende Minimalbeispiel funktioniert:

Open in Online-Editor
\documentclass[tikz=true]{standalone}
\usepackage{luatextra}
\usepackage{fontspec}
  \setmainfont{Arial}
  \setsansfont{Arial}
  \setmonofont{Consolas}
  \defaultfontfeatures{Ligatures=TeX}

\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usetikzlibrary{calc,shapes,arrows, patterns}
\pgfplotsset{compat=newest}

\begin{document}

\newcommand\StartBox{1E-2}

\begin{tikzpicture}
\begin{axis}  
  \addplot[red] coordinates {
    (1, \StartBox)
    (2, 2*\StartBox)
  }; 
\end{axis}
\end{tikzpicture}

\end{document}

Das hingegen nicht:

Open in Online-Editor
\documentclass[tikz=true]{standalone}
\usepackage{luatextra}
\usepackage{fontspec}
  \setmainfont{Arial}
  \setsansfont{Arial}
  \setmonofont{Consolas}
  \defaultfontfeatures{Ligatures=TeX}

\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usetikzlibrary{calc,shapes,arrows, patterns}
\pgfplotsset{compat=newest}

\begin{document}

\newcommand\BoxWidth{8pt}
\newcommand\StartBox{2E-8}

\begin{tikzpicture}[
  boxlabel/.style={pos=.02,left,font=\tiny}
]
\begin{semilogyaxis}[
  % ----- Allgemein -----
  width  = \textwidth,
  height = 7cm,
  enlargelimits =false,
  date coordinates in = x,
  date ZERO = {2015-08-01 00:00},
  every axis plot/.append style={const plot, mark=\empty, line width=\BoxWidth},
  %
  %----- x Achse -----
  xmin = 2015-08-09 00:00,
  xmax = 2015-09-13 00:00,
  xticklabel={\day.\month},
  try min ticks=30,
  major x tick style ={black},
  minor x tick num=3,
  xmajorgrids,
  xminorgrids,
  xlabel = {Jahreshauptrevision 2015},
  xticklabel style = {anchor=east, rotate=90, font=\tiny},
  %
  %----- y-Achse -----
  ymin=1E-8,
  ymax=1E-7,
  ylabel = {CFDF},
  ymajorgrids,
  yminorgrids,
  major y tick style={black},
  minor y tick style={black},
]

  \addplot[red] coordinates {
    (2015-08-11 06:00, \StartBox)
    (2015-09-01 05:00, \StartBox) };

  \addplot[blue] coordinates {
    (2015-08-12 00:00, 4E-8)
    (2015-09-02 12:00, 4E-8) };

% Das hier funktioniert leider nicht:
% 
%  \addplot[green] coordinates {
%    (2015-08-12 00:00, 2*\StartBox)
%    (2015-09-02 12:00, 2*\StartBox) };
\end{semilogyaxis}
\end{tikzpicture}

\end{document}

Irgendwie mag es plötzlich 4*\StartBox nicht.

gefragt 21 Apr '15, 14:27

dzaic's gravatar image

dzaic
631104853
Akzeptiert-Rate: 42%

bearbeitet 21 Apr '15, 16:23

Minibsp. solltest Du m.M.n. immer angeben, damit man daran arbeiten und ausprobieren kann. ;)

(21 Apr '15, 15:36) cis

@dzaic Ich habe unter Wie kann ich die Postionierung von Balken in pgfplots erreichen? eine zweite Antwort gepostet, die Dir für Dein eigentliches Problem vielleicht auch erstmal weiterhilft. Die Frage hier beantwortet sie aber nicht.

(21 Apr '15, 17:20) esdd

Man kann innerhalb der pgfplots-Koordinaten nicht “rechnen”. Das bedeutet, dass da nur Ergebnisse stehen dürfen und keine Ausdrücke (lvalues für Programmierer). Man muss also das Ergebnis vorher ausrechnen und dann einsetzen.

Da die Werte, die wir berechnen wollen sehr klein sind benötigen wir die FPU (Floating Point Unit). Um diese in pgfplots benutzen zu können müssen wir die entsprechenden Instruktionen gruppieren, da die Achsenformatierungen von pgfplots nicht mit der FPU umgehen können.

Außerdem habe ich alles entfernt, was für das Beispiel nicht benötigt wird.

Open in Online-Editor
\documentclass{article}

\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}

\begin{document}

\newcommand\BoxWidth{8pt}
\newcommand\StartBox{2E-8}

\begin{tikzpicture}
\begin{semilogyaxis}[
  date coordinates in = x,
  date ZERO = {2015-08-01 00:00},
  every axis plot/.append style={const plot, mark=\empty, line width=\BoxWidth},
  xmin = 2015-08-09 00:00,
  xmax = 2015-09-13 00:00,
  xticklabel={\day.\month},
  xticklabel style = {anchor=east, rotate=90, font=\tiny},
  try min ticks=30,
  ymin=1E-8,
  ymax=1E-7,
]

  \addplot[red] coordinates {
    (2015-08-11 06:00, \StartBox)
    (2015-09-01 05:00, \StartBox) };

  \addplot[blue] coordinates {
    (2015-08-12 00:00, 4E-8)
    (2015-09-02 12:00, 4E-8) };

  {
    \pgfkeys{/pgf/fpu,/pgf/fpu/output format=sci}
    \pgfmathparse{2*\StartBox}
    \xdef\StartBoxTwo{\pgfmathresult}
  }
  \addplot[green] coordinates {
    (2015-08-12 00:00, \StartBoxTwo)
    (2015-09-02 12:00, \StartBoxTwo) };
\end{semilogyaxis}
\end{tikzpicture}

\end{document}

alt text

Permanenter link

beantwortet 06 Jul '16, 17:34

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

gestellte Frage: 21 Apr '15, 14:27

Frage wurde gesehen: 5,682 Mal

zuletzt geändert: 06 Jul '16, 17:34