pgfplots - Kugeln im 3D Diagramm darstellen

Tabellen und Grafiken erstellen und anordnen


Mr.Goonie
Forum-Anfänger
Forum-Anfänger
Beiträge: 15
Registriert: Mo 6. Jul 2015, 08:09

pgfplots - Kugeln im 3D Diagramm darstellen

Beitrag von Mr.Goonie »

Hallo zusammen,

ich würde gerne Kugeln/Balls im 3D Diagramm ausgeben und komme leider nicht weiter.

Folgende Eigenschaften wären wichtig:
1. Größe der Kugeln (radius) unterschiedlich
2. Jeder Kugel eine eigene Farbe zuweisen
\documentclass{article}
\usepackage{pgfplots}


\begin{document}
\begin{figure}
	\begin{tikzpicture}
		\begin{axis}[width=\textwidth, axis lines=center,
		xlabel={$x$}, ylabel={$y$}, zlabel={$z$},
		xmin=-20, xmax=20,
		ymin=-20, ymax=20,
		zmin=-20, zmax=20,]
	
		\addplot3+[mark=ball, only marks,] coordinates {(10,5,0) (1,2,4) (3,-10,-3)};
		
		\end{axis}
	\end{tikzpicture}
\end{figure}
\end{document}
Wäre echt super, wenn ihr mir helfen könntet.

Vielen Dank und Gruß

LaRiFaRi

Füge drei Plots hinzu

Beitrag von LaRiFaRi »

Du kannst das lösen, indem Du drei Plots einfügst und nicht nur einen. Das sieht dann so aus:
% arara: pdflatex

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12} % wichtig für die Achsenlabels

\begin{document}
	\begin{figure}
		\begin{tikzpicture}
		\begin{axis}[width=\textwidth, axis lines=center,
		xlabel={$x$}, ylabel={$y$}, zlabel={$z$},
		xmin=-20, xmax=20,
		ymin=-20, ymax=20,
		zmin=-20, zmax=20]	
		\addplot3[mark=ball,only marks,ball color=red,mark size=8] coordinates {(10,5,0)}; % plus nicht nötig, geht aber auch. Achte auf die Umrandung der Bälle
		\addplot3[mark=ball,only marks,ball color=green,mark size=4] coordinates {(1,2,4)};
		\addplot3[mark=ball,only marks,ball color=blue,mark size=2] coordinates {(3,-10,-3)};
		\end{axis}
		\end{tikzpicture}
	\end{figure}
\end{document} 

Mr.Goonie
Forum-Anfänger
Forum-Anfänger
Beiträge: 15
Registriert: Mo 6. Jul 2015, 08:09

Beitrag von Mr.Goonie »

ok, ich denke ich habe es jetzt herausgefunden:
 \documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}



\begin{document}
	\begin{tikzpicture}[scale=.05, x = {(0.8cm,0.5cm)}, y={(0cm,2cm)}, z={(1cm,-0.5cm)}]
	\draw[thick,->] (0,-50,0) -- (0,50,0) node[above] {z};
	\draw[thick,->] (0,0,-100) -- (0,0,100) node[right] {x};
	\draw[thick,->] (-100,0,0) -- (100,0,0) node[right] {y};
	
	
	\path (30,0,0) node[circle, color=red!60, fill, inner sep=3]{};
	\path (15,30,0) node[circle, color=blue!60, fill, inner sep=3]{};
	\path (-12,0,30) node[circle, color=black!60, fill, inner sep=6]{};
	\end{tikzpicture}
\end{document}

Mr.Goonie
Forum-Anfänger
Forum-Anfänger
Beiträge: 15
Registriert: Mo 6. Jul 2015, 08:09

Beitrag von Mr.Goonie »

@LaRiFaRi:

danke für Deine Antwort. Ist sogar etwas eleganter als mein Gebastel. Kann man an der Achsenbeschriftung jeweils nur die Grenzen (also 20) anzeigen lassen und wie kann die Ansicht gedreht werden?

Dank und Gruß

Mr.Goonie
Forum-Anfänger
Forum-Anfänger
Beiträge: 15
Registriert: Mo 6. Jul 2015, 08:09

Beitrag von Mr.Goonie »

ah: ...yticklabels={,,}

:lol:

LaRiFaRi

Beitrag von LaRiFaRi »

Das müsste dann so aussehen:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}

\begin{document}
	\begin{figure}
		\begin{tikzpicture}
		\begin{axis}[%
		,width=\textwidth
		,axis lines=center
		,xlabel={$x$}, ylabel={$y$}, zlabel={$z$}
		,xmin=-20, xmax=20, xtick={-20,20} % setzt die Ticks nur da, wo Du sie möchtest
		,ymin=-20, ymax=20, ytick={-20,20}
		,zmin=-20, zmax=20, ztick={-20,20}
		,view={50}{30} % rotation eines 3D Plots. 
		]	
		\addplot3[mark=ball,only marks,ball color=red,mark size=8] coordinates {(10,5,0)};
		\addplot3[mark=ball,only marks,ball color=green,mark size=4] coordinates {(1,2,4)};
		\addplot3[mark=ball,only marks,ball color=blue,mark size=2] coordinates {(3,-10,-3)};
		\end{axis}
		\end{tikzpicture}
	\end{figure}
\end{document}

Mr.Goonie
Forum-Anfänger
Forum-Anfänger
Beiträge: 15
Registriert: Mo 6. Jul 2015, 08:09

Beitrag von Mr.Goonie »

kann es sein, dass \pgfplotset nicht kompatibel mit dem Paket \usepackage[table]{xcolor} ist? Gibt es eine Alternative?

Mr.Goonie
Forum-Anfänger
Forum-Anfänger
Beiträge: 15
Registriert: Mo 6. Jul 2015, 08:09

Beitrag von Mr.Goonie »

ich habe die Option table weggelassen, jetzt geht es. Vielen Dank nochmal für Deine Hilfe.

Gruß

Antworten