Seite 1 von 1

tikzpicture über's Axenlimit hinaus

Verfasst: Mo 25. Jun 2012, 18:52
von elmar.a
Hi,
seit längerem versuche ich einen Teil eines Plots farbig zu hinterlegen. Da in der endgültigen Grafik mehrere Plots nebeneinander gesetzt werden, soll der hinterlegte Abschnitt sich durch alle Plots durchziehen -- er soll also über xmax hinausgehen.

Mein Code sieht momentan wie folgt aus:
\documentclass{minimal}

\usepackage{tikz}														% graphic compiler
\usepackage{pgfplots}												% plotting of data (based on TikZ)

\pgfplotsset{compat=1.5.1}
\usetikzlibrary{calc}


\begin{document}


\begin{tikzpicture}
	\begin{axis}[
			name=plot1,
			height=.6\textheight, width=.23\textwidth,
			axis on top,
			% x axis
			xlabel={RC11-120},
			xlabel near ticks,
			xmin=0, xmax=16,
			xticklabel pos=right,
			% y axis
			ylabel={Age [ka]},
			y dir=reverse,
			ymin=0, ymax=250,
			ytick={0,50,...,250},
			minor y tick num=4,
			]
	\draw[
			draw=lightgray!30!white,
			fill=lightgray!30!white]
			\pgfextra{\pgfpathrectangle{
					\pgfplotspointaxisxy{0}{15}}
					{\pgfplotspointaxisdirectionxy{20}{19}}
					};
	\addplot+[
			no marks, color=black,
			] table[
			x=C. davisiana,
			y=Age,
			header=has colnames,
			col sep=semicolon,
			row sep=newline,
			] {rc11120_ageLR_depthCd.csv};
	\end{axis}
	\begin{axis}[
			name=plot2,
			at={($(plot1.east)+(.02\textwidth,0)$)},
			anchor=west,
			height=.6\textheight, width=.23\textwidth,
			axis on top,
			% x axis
			xlabel={PS2082-1},
			xlabel near ticks,
			xmin=0, xmax=25,
			xticklabel pos=right,
			% y axis
			y dir=reverse,
			ymin=0, ymax=250,
			ytick={0,50,...,250},
			minor y tick num=4,
			yticklabels=\empty,
			]
	\addplot+[
			no marks,
			color=black,
			] table[
			x=C. davisiana,
			y=Age,
			header=has colnames,
			col sep=semicolon,
			row sep=newline,
			] {ps20821_ageLR_depthCd.csv};
	\end{axis}
\end{tikzpicture}
			

\end{document}
Aussehen soll das Ganze später in etwa wie die Graphik im Anhang (erstellt mit Grapher 8)....

Ist dies möglich? Wenn ja, wie?


Gruß und besten Dank!

Verfasst: Di 26. Jun 2012, 11:26
von bloodworks
Hallo in diesem Fall wie auch in allen anderen wäre es hilfreich ein vollständiges und lauffähiges Minimalbeispiel [2] zu haben.

Verfasst: Di 26. Jun 2012, 15:05
von elmar.a
Sorry, das war mein erster Forenbeitrag zum Thema LaTeX überhaupt, dementsprechend bin ich die Gepflogenheiten hier noch nicht wirklich gewöhnt.
Ich hoffe das folgende Beispiel entspricht den allgemeinen Anforderungen eines Minimalbeispiels?!?
\documentclass{minimal}
\usepackage{
	tikz,
	pgfplots
	}
\pgfplotsset{compat=1.5.1}

\begin{document}

\begin{tikzpicture}
	\begin{axis}[
			xmin=0, xmax=16,
			ymin=0, ymax=250,
			axis on top,
			]
	\draw[fill=red]			% roter Balken soll über xmax hinausgehen!
			\pgfextra{\pgfpathrectangle{
					\pgfplotspointaxisxy{0}{15}}
					{\pgfplotspointaxisdirectionxy{20}{19}}
					};
	\end{axis}
\end{tikzpicture}
			
\end{document}
Wie gesagt -- der (jetzt rote) Balken soll über xmax=16 hinausgehen.

Gruß,
elmar.a

Verfasst: Di 26. Jun 2012, 15:18
von bloodworks
Hi du kannst ganz frech außerhalb der Axis arbeiten:
\documentclass{minimal} 
\usepackage{
    pgfplots 
    } 
\pgfplotsset{compat=1.5.1} 

\begin{document} 

\begin{tikzpicture} 
    \begin{axis}[ 
          xmin=0, xmax=16, 
          ymin=0, ymax=250, 
          axis on top, enlarge x limits=false, area style,
          ] 

 \addplot coordinates
{(0,0) (0,100) (17,100) (17,0)}\closedcycle;
       \addplot coordinates
{(0,0)(16,50) };
    \end{axis} 
    \draw[fill=blue, opacity=.5] (0,0) rectangle (10,1);
\end{tikzpicture} 
           
\end{document} 
  

Verfasst: Di 26. Jun 2012, 15:36
von elmar.a
... in dem Fall kann ich aber keine exakten (achsenbasierten) Start-/Endkoordinaten für das Rechteck angeben, oder?!

Verfasst: Di 26. Jun 2012, 16:20
von bloodworks
äh nö aber man kann ja noch das Zeichenn etwas verzögern:
\documentclass{minimal} 
\usepackage{
    pgfplots 
    } 
\pgfplotsset{compat=newest} 

\begin{document} 

\begin{tikzpicture} 
    \begin{axis}[    xmin=0, xmax=16, 
          ymin=0, ymax=250, 
          axis on top, enlarge x limits=false, area style,%
    after end axis/.code={ \fill[red, opacity=.5] (axis cs:0,0) rectangle (axis cs:20,50); }%
          %
          ] %

       \addplot coordinates {(0,0)(16,50) };
\end{axis}

\end{tikzpicture} 


           
\end{document} 
  
Das steht sogar in der Doku... Das liegt natürlich über den plots

Verfasst: Di 26. Jun 2012, 18:42
von elmar.a
Ah super, das sieht doch schon ganz gut aus!
Besten Dank soweit!!

Verfasst: Mi 27. Jun 2012, 21:18
von feuersaenger
Hi elmar.a,

Du kannst das "einfach frech ueber den Rand hinauszeichnen" auch dadurch erreichen, dass Du pgfplots den Rand wegnimmst.

Dazu brauchst Du

...
\begin{axis}[..., clip = false]
...

und schon wird alles, was ueber die limits hinausgeht, mit geplottet.

Mit liebem Gruss

Christian

Verfasst: Mi 27. Jun 2012, 22:25
von elmar.a
Nice, über die Option war ich bislang auch noch nicht gestolpert!

Danke, ich denke mit den Lösungsvorschlägen werde ich das Ganze ohne Probleme zusammenbasteln können!