PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : tikz: Beschriftung soll Kurve folgen



msthab
23-01-2017, 14:51
Hallo,
das Thema "Text biegen" bringt mich auf eine andere Frage:
Ich möchte, dass im tikzpicture eine Beschriftung dem Funktionsgraphen folgt, der mittels \datavisualization erstellt wurde.
Im Minimalbesipiel soll der Text der Hyperbel folgen und nicht einfach linear "drüberschreiben". Ist sowas möglich?
Im `texdoc pgfmanual' ist in Kap 24.3 zwar der decoration-Befehl beschrieben, aber ich schaffe es nicht, diesen mit meiner "Funktion" zu verknüpfen.

Vielen Dank

Manfred


\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.function s}
\usetikzlibrary{plotmarks}
\makeatother
\usepackage{babel}
\begin{document}


\begin{tikzpicture}
\datavisualization [school book axes,visualize as smooth line/.list={a,b},
a={style ={red,very thick},label in data={text=$\leftarrow$ isotherme Kompression, node style=sloped, when=x is 2}},
all axes={grid},
x axis={length=10cm,
ticks={none},
label= $V$},
y axis={length=5cm,
ticks={many},
label= $p/10^5$},
data/format=function
]
data [set=a] {
var x : interval [1:5.1] step 0.1;
func y = 5*(1/\value x);
}
data [set=b] {
var x : interval [1:5.1] step 0.1;
func y = 5*((1/\value x)^(1.4));
} ;
\end{tikzpicture}

rais
23-01-2017, 22:08
Im `texdoc pgfmanual' ist in Kap 24.3 zwar der decoration-Befehl beschrieben, aber ich schaffe es nicht, diesen mit meiner "Funktion" zu verknüpfen.

was hast Du denn wie versucht?

VG

msthab
24-01-2017, 12:35
Hallo,

also im Manual steht das Beispiel für eine Elipse wie folgt drin:


\node at (1.5,1) [inner sep=6mm,fill=red!20,decorate,ellipse,decoration=
{text along path,text={This is getting silly}}] {Ellipse};

Ich habe Verschiedenes probiert, um die Anweisungen mit meiner Funktion zu "koppeln", z.B. habe ich den node-style verändert:

a={style ={red,very thick}, node style=decorate, decoration={text along path,text={$\leftarrow$ isotherme Kompression}}when=x is 2}

oder unten für den path statt der "Ellipse" die Funktion eingetragen:

\node at (2,2) [inner sep=6mm,decorate,decoration= {text along path,text={$\leftarrow$ isotherme Kompression}}] {set=a};


Funktioniert leider alles nicht.
Hier das komplette Beispiel, das nicht funktioniert:

\documentclass[english]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{url}

\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.function s}
\usetikzlibrary{plotmarks}
\usetikzlibrary{decorations}
\makeatother
\usepackage{babel}
\begin{document}


\begin{tikzpicture}
\datavisualization [school book axes,visualize as smooth line/.list={a,b},
%a={style ={red,very thick},label in data={text=$\leftarrow$ isotherme Kompression, node style=sloped, when=x is 2}}, %das funktioniert
a={style ={red,very thick}, node style=decorate, decoration={text along path,text={$\leftarrow$ isotherme Kompression}}when=x is 2}%funktioniert nicht
all axes={grid},
x axis={length=10cm,
ticks={none},
label= $V$},
y axis={length=5cm,
ticks={many},
label= $p/10^5$},
data/format=function
]
data [set=a] {
var x : interval [1:5.1] step 0.1;
func y = 5*(1/\value x);
}
data [set=b] {
var x : interval [1:5.1] step 0.1;
func y = 5*((1/\value x)^(1.4));
};
\node at (2,2) [inner sep=6mm,fill=red!20,decorate,decoration= {text along path,text={$\leftarrow$ isotherme Kompression}}] {set=a}; %Funktioniert nicht
\end{tikzpicture}

\end{document}

rais
25-01-2017, 01:32
oder unten für den path statt der "Ellipse" die Funktion eingetragen:

\node at (2,2) [inner sep=6mm,decorate,decoration= {text along path,text={$\leftarrow$ isotherme Kompression}}] {set=a};


nö, hier hast Du lediglich den Text des Knotens ersetzt, statt `Ellipse' wird dann bestenfalls `set=a' erscheinen.

Deinem Beispiel fehlt zumindest die decorations.text-library, ohne die kannst Du Dinge wie `text along path' nicht nutzen.

$\leftarrow$ lässt sich auch nicht direkt innerhalb so einer Textdekoration nutzen, der \leftarrow-Befehl muß zusätzlich geklammert werden (${\leftarrow}$)

Warum es mit der Kombination Datenvisualisierung/Textdekoration nicht klappen will, dazu kann ich derzeit nix sagen, aber vllt hilft Dir ja eine Annäherung:


\documentclass[english]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{url}

\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.function s}
\usetikzlibrary{plotmarks}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.text}
\usepackage{babel}
\begin{document}


\begin{tikzpicture}
\datavisualization [school book axes,visualize as smooth line/.list={a,b},
a={style ={red,very thick},label in data={text=$\leftarrow$ isotherme Kompression, node style=sloped, when=x is 2}}, %das funktioniert
%a={style ={red,very thick}, node style={decorate, decoration={text along path,text={isotherme Kompression}}}, when=x is 2}%funktioniert nicht
all axes={grid},
x axis={length=10cm,
ticks={none},
label= $V$},
y axis={length=5cm,
ticks={many},
label= $p/10^5$},
data/format=function
]
data [set=a] {
var x : interval [1:5.1] step 0.1;
func y = 5*(1/\value x);
}
data [set=b] {
var x : interval [1:5.1] step 0.1;
func y = 5*((1/\value x)^(1.4));
};
\node at (2,2) [inner sep=6mm,fill=red!20,decorate,decoration= {text along path,text={${\leftarrow}$ isotherme Kompression}}] {set=a}; %Funktioniert, aber tut wohl nicht das, was Du erwartest
\draw[blue] (2,5) .. controls (3.7,1.5) and (6.15,1.6) .. (10,1);
\draw[decorate, decoration={text along path, text={${\leftarrow}$ isotherme Kompression}, text align={align=center}}] (2,5) .. controls (3.7,1.5) and (6.15,1.6) .. (10,1);
\end{tikzpicture}

\end{document}

VG

msthab
25-01-2017, 08:49
Hallo,

vielen herzlichen Dank für Deinen Beitrag. Deine Idee, den draw-Befehl zu nutzen hat mich auf die (fast perfekte) Lösung gebracht

\draw[variable=\x, domain=1:5,decorate, decoration={text along path, text={${\leftarrow}$ isotherme Kompression},raise=1ex,text align={center} }] plot ({\x},{5/(\x)});

Siehe auch komplettes Beispiel unten.

Einziges Problem: Die \x Werte entsprechen nicht dem x-Werten in der \datavisualization- Umgebung. Ich muss exakt den Maßstab 1 Einheit = 1 cm verwenden (oder umrechnen).
Daher meine nächste Frage:
Wie kann ich die \x Werte im draw-Befehl gleich den x-Werten in der \datavisualization setzen? Ich weiß, es gibt den "visualization cs" Befehl. Aber wie setze ich den hier ein?


\documentclass[english]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{url}

\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.function s}
\usetikzlibrary{plotmarks}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.text}
\usepackage{babel}
\begin{document}


\begin{tikzpicture}
\datavisualization [school book axes,visualize as smooth line/.list={a,b},
all axes={grid},
x axis={length=5cm,
ticks={many},
label= $V$},
y axis={length=5cm,
ticks={many},
label= $p/10^5$},
data/format=function
]
data [set=a] {
var x : interval [1:5.1] step 0.1;
func y = (5/\value x);
}
data [set=b] {
var x : interval [1:5.1] step 0.1;
func y = 5*((1/\value x)^(1.4));
};
\draw[variable=\x, domain=1:5,decorate, decoration={text along path, text={${\leftarrow}$ isotherme Kompression},raise=1ex,text align={center} }] plot ({\x},{5/(\x)});
\end{tikzpicture}

\end{document}

rais
25-01-2017, 20:49
Einziges Problem: Die \x Werte entsprechen nicht dem x-Werten in der \datavisualization- Umgebung. Ich muss exakt den Maßstab 1 Einheit = 1 cm verwenden (oder umrechnen).

Das versteh ich noch nicht. Genügt es nicht, im \draw bei domain den selben Bereich anzugeben wie im interval zuvor beim entsprechenden Datensatz?

VG

msthab
26-01-2017, 09:46
Um das (neue) Problem etwas deutlicher zu machen, habe ich die Grafik wie folgt geändert:

-Die Funktion y=x genommen
-Die Decoration rausgenommen
-Die Funktion einmal in der \datavisualization Umgebung (rot) und einmal mit \draw gezeichnet
-zwei Punkte mit Draw ergänzt (identische Koordinaten) dabei einmal die Option"visualization cs:" verwendet (rot)

Deutlich ist zu erkennen, dass die schwarzen Grafiken ein ganz anderes Koordinatensystem nutzen (nämlich auf cm-Basis) als die eigentliche \datavisualization Umgebung.
Mit der "visualization cs:" Option kann ich dies bei eizelnen nodes korrigieren, aber wie setze ich die Option bei plot ein?


\documentclass[english]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{url}

\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.function s}
\usetikzlibrary{plotmarks}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.text}
\usepackage{babel}
\begin{document}


\begin{tikzpicture}
\datavisualization [school book axes,visualize as smooth line/.list={a,b},
all axes={grid},
a={style ={red,very thick}},
x axis={length=11cm,
ticks={many},
label= $x$},
y axis={length=4cm,
ticks={many},
label= $y$},
data/format=function
]
data [set=a] {
var x : interval [1:5.1] step 0.1;
func y = (\value x);
}
info {
\draw[variable=\x, domain=1:5.1] plot ({\x},{\x});
\draw [red] (visualization cs: x=5, y=1) circle [radius=3pt]
node [above,font=\footnotesize] {richtige Koordinaten mit cs};
\draw (5,1) circle [radius=3pt]
node [below,font=\footnotesize] {falsche Koordinaten ohne cs};
};
\end{tikzpicture}

\end{document}

rais
26-01-2017, 23:33
Um das (neue) Problem etwas deutlicher zu machen, habe ich die Grafik wie folgt geändert:

-Die Funktion y=x genommen
-Die Decoration rausgenommen
-Die Funktion einmal in der \datavisualization Umgebung (rot) und einmal mit \draw gezeichnet
-zwei Punkte mit Draw ergänzt (identische Koordinaten) dabei einmal die Option"visualization cs:" verwendet (rot)

Deutlich ist zu erkennen, dass die schwarzen Grafiken ein ganz anderes Koordinatensystem nutzen (nämlich auf cm-Basis) als die eigentliche \datavisualization Umgebung.

hier mein Versuch, die beiden Geraden über einander zu ziehen:


\documentclass[english]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{url}

\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.function s}
\usetikzlibrary{plotmarks}
\usetikzlibrary{calc}
\usetikzlibrary{decorations}
\usetikzlibrary{decorations.text}
\usepackage{babel}
\newlength\mya
\newlength\myb
\newcommand*\myxa{}
\newcommand*\myxb{}
\makeatletter
\newlength\my@tmp
\newcommand*\ptocm[2]{%
\setlength\my@tmp{\dimexpr0.03514598#1\relax}% 0.03514598 cm/pt = (2.54 cm/in) / (72.27 pt/in)
\edef#2{\strip@pt\my@tmp}%
}
\makeatother

\begin{document}


\begin{tikzpicture}
\datavisualization [school book axes,visualize as smooth line/.list={a,b},
all axes={grid},
a={style ={red,very thick}},
x axis={length=11cm,
ticks={many},
label= $x$},
y axis={length=4cm,
ticks={many},
label= $y$},
data/format=function
]
data [set=a] {
var x : interval [1:5.1] step 0.1;
func y = (\value x);
}
info {
\coordinate (A) at (visualization cs: x=1, y=1);
\coordinate (B) at (visualization cs: x=5, y=1);
\pgfextractx{\mya}{\pgfpointanchor{A}{center}}% siehe auch http://tex.stackexchange.com/questions/14021/extract-the-x-y-part-from-a-coordinate-in-pgfplots
\pgfextractx{\myb}{\pgfpointanchor{B}{center}}
\ptocm{\mya}{\myxa}%
\ptocm{\myb}{\myxb}%
\draw[blue] (A) -- (B);
\draw[variable=\x, domain=\myxa:\myxb] plot ({\x},{0.3636*\x});% 0.3636 = y axis length / x axis length ( = 4 cm / 11 cm)
\draw [red] (visualization cs: x=5, y=1) circle [radius=3pt]
node [above,font=\footnotesize] {richtige Koordinaten mit cs};
\draw (5,1) circle [radius=3pt]
node [below,font=\footnotesize] {falsche Koordinaten ohne cs};
};
\end{tikzpicture}

\end{document}

Ob es Dir bei Deinem eigentlichen Problem hilft, kann ich nicht sagen (und bin inzwischen auch zu müde, in der Hinsicht heute noch was zu testen)

VG

msthab
27-01-2017, 13:27
Vielen Dank,

mit der Koordiantentransformation funktioniert es!

Noch einmal vielen Dank für Deine Hilfe!!!

Manfred