Ich habe folgende beiden "Probleme".

1) Die "minor y ticks" werden nicht angezeigt.

2) Ich möchte gerne die dickeren, farbigen Balken so positionieren, dass diese unterhalb der schwarzen Linie sind, jedoch gleichmässig übereinander verteilt. Momentan positioniere ich diese vertikal mit der y-Koordinate. Da die Skala aber logaritmisch ist, überlappen diese sich leider. Dies bedeutet, dass ich die Balken bzgl. des Anfangs und des Endes mit der x-Koordinate (Datum) bestimmen will, die vertikale Positioierung irgendwie "relativ" zum y-min Wert sein soll. Gäbe es noch eine andere Art der vertikalen Positionierung als die über y-Koordinaten?

Open in Online-Editor
\documentclass[tikz=true]{standalone}
\usepackage{fontspec}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usetikzlibrary{shapes,arrows, patterns}
\pgfplotsset{compat=newest}

\begin{document}

\newcommand\BoxWidth{5pt}

\begin{tikzpicture}
\newcommand\PosNode{0.02}
\begin{semilogyaxis}[
  % ----- Allgemein -----
  width  = \textwidth,
  height = 5cm,
  enlargelimits =false,
  date coordinates in = x,
  date ZERO = {2015-08-01 00:00},
  every axis plot/.append style={const plot, mark=\empty},
  %
  %----- x Achse -----
  xmin = 2015-08-09 00:00,
  xmax = 2015-09-13 00:00,
  try min ticks=30,  
  major x tick style={black},
  minor x tick num=3,
  minor x tick style={draw=none},
  xmajorgrids,
  xminorgrids,
  xticklabel style = {anchor=east, rotate=90, font=\tiny},
  %
  %----- y-Achse -----
  ymin=1E-8,
  ymax=1E-4,
  ylabel = {CFDF},
  major y tick style={black},
  minor y tick style={black},
]

\addplot[black, line width=1.5pt] coordinates {
  (2015-08-09 08:00, 1.00E-6) % POS 0
  (2015-08-10 15:00, 1.50E-6) % POS 2-3
  (2015-08-11 03:00, 2.00E-6) % POS 4-5
  (2015-08-11 06:00, 2.50E-6) % POS 6
  (2015-08-11 18:00, 3.00E-6) % POS 7-9
  (2015-08-13 03:00, 3.50E-6) % POS 10
  (2015-09-05 12:00, 4.00E-6) % POS 11-12
  (2015-09-07 04:00, 4.50E-6) % POS 13
  (2015-09-10 09:00, 5.00E-6) % POS 14-16
  (2015-09-10 15:00, 5.50E-6) % POS 17-18
  (2015-09-11 00:00, 6.00E-6) % POS 19-20
  (2015-09-13 00:00, 1.00E-6) % POS 19-20
};

  % CRD
  \addplot[red, line width=\BoxWidth]  coordinates {
    (2015-08-11 06:00, 1E-7)
    (2015-09-01 05:00, 1E-7) }
    node[pos=\PosNode, left] {\tiny CRD};

  % SEHR
  \addplot[blue, line width=\BoxWidth] coordinates {
    (2015-08-12 00:00, 2E-7)
    (2015-09-02 12:00, 2E-7) }
    node[pos=\PosNode, left] {\tiny SEHR};

  % Div. 21
  \addplot[green, line width=\BoxWidth] coordinates {
    (2015-08-13 03:00, 3E-7)
    (2015-08-23 07:00, 3E-7) }
    node[pos=\PosNode, left] {\tiny Div.21};

  % Div. 11
  \addplot[orange, line width=\BoxWidth] coordinates {
    (2015-08-23 07:00, 4E-7)
    (2015-09-04 22:00, 4E-7) }
    node[pos=\PosNode, left] {\tiny Div.11};

\end{semilogyaxis}
\end{tikzpicture}

\end{document}

gefragt 21 Apr '15, 10:45

dzaic's gravatar image

dzaic
631104853
Akzeptiert-Rate: 42%

bearbeitet 21 Apr '15, 13:54


Aus der Dokumentation von pgfplots zu der Option minor y tick num:

Minor ticks will be disabled if the major ticks don't have the same distance and they are currently only available for linear axes (not for logarithmic ones).

Das heißt, die Angabe der Option minor y tick num hat keinen Einfluss. Allerdings kann man auch manuell festlegen, wo yticks und minor yticks gesetzt werden.

Wenn die vertikalen Abstände zwischen den Balken bei einer logarithmischen Achse gleich sein müssen, dann muss der Quotient der y-Koordinaten von zwei aufeinanderfolgenden Balken gleich sein. Bei linearen Achsen wäre es dagegen die Differenz. Im MWE könnte man zum Beispiel den Faktor 2 verwenden, um aus der y-Koordinate eines Balkens die des darüber stehenden Balkens zu ermitteln.

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

\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usetikzlibrary{shapes,arrows, patterns}
\pgfplotsset{compat=1.12}
\begin{document}
\newcommand\BoxWidth{5pt}
\begin{tikzpicture}[
  boxlabel/.style={pos=.02,left,font=\tiny}
]
\begin{semilogyaxis}[
  % ----- Allgemein -----
  width  = \textwidth,
  height = 5cm,
  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,
  try min ticks=30,  
  major x tick style={black},
  minor x tick num=3,
  minor x tick style={draw=none},
  xmajorgrids,
  xminorgrids,
  xticklabel style = {anchor=east, rotate=90, font=\tiny},
  %
  %----- y-Achse -----
  ymin=1E-8,
  ymax=1E-4,
  ylabel = {CFDF},
  major y tick style={black},
  minor y tick style={black},
  ytick={1E-5,1E-6},
  minor ytick={8E-7,2E-6,4E-6,6E-6,8E-6,2E-5,4E-5,6E-5,8E-5},
]

\addplot[black, line width=1.5pt] coordinates {
  (2015-08-09 08:00, 1.00E-6) % POS 0
  (2015-08-10 15:00, 1.50E-6) % POS 2-3
  (2015-08-11 03:00, 2.00E-6) % POS 4-5
  (2015-08-11 06:00, 2.50E-6) % POS 6
  (2015-08-11 18:00, 3.00E-6) % POS 7-9
  (2015-08-13 03:00, 3.50E-6) % POS 10
  (2015-09-05 12:00, 4.00E-6) % POS 11-12
  (2015-09-07 04:00, 4.50E-6) % POS 13
  (2015-09-10 09:00, 5.00E-6) % POS 14-16
  (2015-09-10 15:00, 5.50E-6) % POS 17-18
  (2015-09-11 00:00, 6.00E-6) % POS 19-20
  (2015-09-13 00:00, 1.00E-6) % POS 19-20
};
  % CRD
  \addplot[red]  coordinates {
    (2015-08-11 06:00, .5E-7)
    (2015-09-01 05:00, .5E-7) }
    node[boxlabel] {CRD};
  % SEHR
  \addplot[blue] coordinates {
    (2015-08-12 00:00, 1E-7)
    (2015-09-02 12:00, 1E-7) }
    node[boxlabel] {SEHR};
  % Div. 21
  \addplot[green] coordinates {
    (2015-08-13 03:00, 2E-7)
    (2015-08-23 07:00, 2E-7) }
    node[boxlabel] {Div.21};
  % Div. 11
  \addplot[orange] coordinates {
    (2015-08-23 07:00, 4E-7)
    (2015-09-04 22:00, 4E-7) }
    node[boxlabel] {Div.11};
\end{semilogyaxis}
\end{tikzpicture}
\end{document}

alt text

Permanenter link

beantwortet 21 Apr '15, 13:57

esdd's gravatar image

esdd
17.7k254256
Akzeptiert-Rate: 62%

@esdd Herzlichen Dank - insbesondere auch für die anderen Verbesserungen in meinem Code.

(21 Apr '15, 14:12) dzaic

Alternativ zu meiner anderen Antwort kannst Du auch die Option yshift=<dimension> für die Plots nutzen. Dann kannst Du den Abstand zwischen den Balken in pt oder mm festlegen:

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

\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usetikzlibrary{shapes,arrows, patterns}
\pgfplotsset{compat=1.12}
\begin{document}
\newcommand\BoxWidth{5pt}
\newcommand\BoxSep{3pt}% Abstand zwischen Balken

\begin{tikzpicture}[
  boxlabel/.style={pos=.02,left,font=\tiny},
  boxshift/.style={yshift=#1*(\BoxWidth+\BoxSep)}
]
\newcommand\StartBox{4E-8}

\begin{semilogyaxis}[
  % ----- Allgemein -----
  width  = \textwidth,
  height = 5cm,
  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,
  try min ticks=30,  
  major x tick style={black},
  minor x tick num=3,
  minor x tick style={draw=none},
  xmajorgrids,
  xminorgrids,
  xticklabel style = {anchor=east, rotate=90, font=\tiny},
  %
  %----- y-Achse -----
  ymin=1E-8,
  ymax=1E-4,
  ylabel = {CFDF},
  major y tick style={black},
  minor y tick style={black},
  ytick={1E-5,1E-6},
  minor ytick={8E-7,2E-6,4E-6,6E-6,8E-6,2E-5,4E-5,6E-5,8E-5},
]

\addplot[black, line width=1.5pt] coordinates {
  (2015-08-09 08:00, 1.00E-6) % POS 0
  (2015-08-10 15:00, 1.50E-6) % POS 2-3
  (2015-08-11 03:00, 2.00E-6) % POS 4-5
  (2015-08-11 06:00, 2.50E-6) % POS 6
  (2015-08-11 18:00, 3.00E-6) % POS 7-9
  (2015-08-13 03:00, 3.50E-6) % POS 10
  (2015-09-05 12:00, 4.00E-6) % POS 11-12
  (2015-09-07 04:00, 4.50E-6) % POS 13
  (2015-09-10 09:00, 5.00E-6) % POS 14-16
  (2015-09-10 15:00, 5.50E-6) % POS 17-18
  (2015-09-11 00:00, 6.00E-6) % POS 19-20
  (2015-09-13 00:00, 1.00E-6) % POS 19-20
};
  % CRD
  \addplot[red]  coordinates {
    (2015-08-11 06:00,\StartBox)
    (2015-09-01 05:00,\StartBox) }
    node[boxlabel] {CRD};
  % SEHR
  \addplot[blue,boxshift=1] coordinates {
    (2015-08-12 00:00,\StartBox)
    (2015-09-02 12:00,\StartBox) }
    node[boxlabel] {SEHR};
  % Div. 21
  \addplot[green,boxshift=2] plot coordinates {
    (2015-08-13 03:00,\StartBox)
    (2015-08-23 07:00,\StartBox) }
    node[boxlabel] {Div.21};
  % Div. 11
  \addplot[orange,boxshift=3] coordinates {
    (2015-08-23 07:00,\StartBox)
    (2015-09-04 22:00,\StartBox) }
    node[boxlabel] {Div.11};
\end{semilogyaxis}
\end{tikzpicture}
\end{document}

alt text

Man kann dafür auch eine cycle list verwenden:

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

\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usetikzlibrary{shapes,arrows, patterns}
\pgfplotsset{compat=1.12}
\begin{document}
\newcommand\BoxWidth{5pt}
\newcommand\BoxSep{3pt}

\begin{tikzpicture}[
  boxlabel/.style={pos=.02,left,font=\tiny},
  boxshift/.style={yshift=#1*(\BoxWidth+\BoxSep)}
]
\newcommand\StartBox{.4E-7}
\begin{semilogyaxis}[
  % ----- Allgemein -----
  width  = \textwidth,
  height = 5cm,
  enlargelimits =false,
  date coordinates in = x,
  date ZERO = {2015-08-01 00:00},
  every axis plot/.append style={const plot,line width=\BoxWidth},
  %
  %----- x Achse -----
  xmin = 2015-08-09 00:00,
  xmax = 2015-09-13 00:00,
  try min ticks=30,  
  major x tick style={black},
  minor x tick num=3,
  minor x tick style={draw=none},
  xmajorgrids,
  xminorgrids,
  xticklabel style = {anchor=east, rotate=90, font=\tiny},
  %
  %----- y-Achse -----
  ymin=1E-8,
  ymax=1E-4,
  ylabel = {CFDF},
  major y tick style={black},
  minor y tick style={black},
  ytick={1E-5,1E-6},
  minor ytick={8E-7,2E-6,4E-6,6E-6,8E-6,2E-5,4E-5,6E-5,8E-5},
  %
  %----- cycle list -----
  cycle list={%
    black,line width=1.5pt\\%
    red\\%
    blue,boxshift=1\\%
    green,boxshift=2\\%
    orange,boxshift=3\\%
  }
]

\addplot coordinates {
  (2015-08-09 08:00, 1.00E-6) % POS 0
  (2015-08-10 15:00, 1.50E-6) % POS 2-3
  (2015-08-11 03:00, 2.00E-6) % POS 4-5
  (2015-08-11 06:00, 2.50E-6) % POS 6
  (2015-08-11 18:00, 3.00E-6) % POS 7-9
  (2015-08-13 03:00, 3.50E-6) % POS 10
  (2015-09-05 12:00, 4.00E-6) % POS 11-12
  (2015-09-07 04:00, 4.50E-6) % POS 13
  (2015-09-10 09:00, 5.00E-6) % POS 14-16
  (2015-09-10 15:00, 5.50E-6) % POS 17-18
  (2015-09-11 00:00, 6.00E-6) % POS 19-20
  (2015-09-13 00:00, 1.00E-6) % POS 19-20
};
  % CRD
  \addplot  coordinates {
    (2015-08-11 06:00,\StartBox)
    (2015-09-01 05:00,\StartBox) }
    node[boxlabel] {CRD};
  % SEHR
  \addplot coordinates {
    (2015-08-12 00:00,\StartBox)
    (2015-09-02 12:00,\StartBox) }
    node[boxlabel] {SEHR};
  % Div. 21
  \addplot coordinates {
    (2015-08-13 03:00,\StartBox)
    (2015-08-23 07:00,\StartBox) }
    node[boxlabel] {Div.21};
  % Div. 11
  \addplot coordinates {
    (2015-08-23 07:00,\StartBox)
    (2015-09-04 22:00,\StartBox) }
    node[boxlabel] {Div.11};
\end{semilogyaxis}
\end{tikzpicture}
\end{document}

Das Ergebnis ist das gleiche wie oben.

Permanenter link

beantwortet 21 Apr '15, 17:14

esdd's gravatar image

esdd
17.7k254256
Akzeptiert-Rate: 62%

@esdd Wieder einmal eine hervorragende Antwort, für die ich mich recht herzlich bedanken möchte. Pgfplots ist wahrlich ein mächtiges Werkzeug, und der Autor sollte den Texnobelpreis nominiert werden. :-)

(22 Apr '15, 17:04) dzaic
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, 10:45

Frage wurde gesehen: 8,012 Mal

zuletzt geändert: 22 Apr '15, 17:04