Überarbeitungsverlauf[Zurück]
Klicke auf Einblenden/Ausblenden von Überarbeitungen 4
Bessere Adaptierung

07 Jun '18, 22:35

Gel%C3%B6scht's gravatar image

Gelöscht
(ausgesetzt)

Hier ist ein Vorschlag. pgfplots hat die Möglichkeit, in einem scatter plot Würfel zu zeichnen und man kann die Längen der Kanten ändern. \documentclass[tikz,border=3.14pt]{standalone} \usetikzlibrary{calc} \usepackage{pgfplots} \usepackage{pgfplotstable} \pgfplotsset{compat=1.15} \pgfplotsset{compat=1.16} % from https://tex.stackexchange.com/a/102770/121799 \def\pgfplotsinvokeiflessthan#1#2#3#4{% \pgfkeysvalueof{/pgfplots/iflessthan/.@cmd}{#1}{#2}{#3}{#4}\pgfeov }% \def\pgfplotsmulticmpthree#1#2#3#4#5#6\do#7#8{% \pgfplotsset{float <}% \pgfplotsinvokeiflessthan{#1}{#4}{% % first key <: #7% }{% \pgfplotsinvokeiflessthan{#4}{#1}{% % first key >: #8% }{% % first key ==: \pgfplotsset{float <}% \pgfplotsinvokeiflessthan{#2}{#5}{% % second key < #7% }{% \pgfplotsinvokeiflessthan{#5}{#2}{% % second key > #8% }{% % second key == \pgfplotsset{float <}% \pgfplotsinvokeiflessthan{#3}{#6}{% % third key < #7% }{% % third key >= #8% }% }% }% }% }% }% \begin{document} \pgfplotstableread[col sep=comma,header=true]{% x,y,color,myvalue 2,3,1,100 4,3,2,3 2,7,3,0.75 7,7,4,45 8,5,2,3 2,5,1,10 4,-4,2,1 4,1,3,75 5,-1,4,4 5,2,2,3 1,-2,1,10 2,5,2,5 3,-8,3,75 4,5,4,42 7,-2,2,2 }{\datatable} % \pgfplotstablesort[col %\pgfplotstablesort[col sep=comma,header=true]\resulttable{\datatable} \pgfplotstablesort[create on use/sortkey/.style={ create col/assign/.code={% \edef\entry{{\thisrow{x}}{\thisrow{y}}{\thisrow{myvalue}}}% \pgfkeyslet{/pgfplots/table/create col/next content}\entry } }, sort key=sortkey, sort cmp={% iflessthan/.code args={#1#2#3#4}{% \edef\temp{#1#2}% \expandafter\pgfplotsmulticmpthree\temp\do{#3}{#4}% }, }, sort, columns/Mtx/.style={string type}, columns/Kind/.style={string type},]\resulttable{\datatable} \begin{tikzpicture}%[x={(0.866cm,-0.5cm)},y={(0.866cm,0.5cm)},z={(0cm,1 cm)}] \pgfplotsset{set layers} \begin{axis}[% from section 4.6.4 of the pgfplotsmanual view={120}{40}, width=320pt, height=280pt, z buffer=none, xmin=-1,xmax=8, xmin=-1,xmax=9, ymin=-10,ymax=8, zmin=0,zmax=200, enlargelimits=upper, ztick={0,100,200}, zticklabels={0,50,100}, % here one has to "cheat" % meaning that one has to put labels which are the actual value % divided by 2. This is because the bars will be centered at these % values xtick=data, extra tick style={grid=major}, ytick=data, grid=minor, xlabel={$x$}, ylabel={$y$}, zlabel={$z$}, minor tick num=1, point meta=explicit, colormap name=viridis, scatter/use mapped color={ draw=mapped color,fill=mapped color!70}, execute at begin plot={} ] \path let \p1=($(axis cs:0,0,1)-(axis cs:0,0,0)$) in \pgfextra{\pgfmathsetmacro{\conv}{2*\y1} \typeout{Kindly\space\space consider\space setting\space the\space prefactor\space of\space z\space to\space \conv}}; \addplot3 [visualization depends on={z on={ 0.9952*z \as \myz}, \myz}, % you'll get told how to adjust the prefactor scatter/@pre marker code/.append style={/pgfplots/cube/size z=\myz},% z=\myz pt},% scatter,only marks, mark=cube*,mark size=5] size=5,opacity=1] table[x expr={\thisrow{x}},y expr={\thisrow{y}},z expr={\thisrow{myvalue}}, expr={1*\thisrow{myvalue}}, meta expr={\thisrow{color}} ] \resulttable; \end{axis} \end{tikzpicture} \end{document} [![alt text][1]][1] **UPDATE**: Mein ursprünglicher Code hatte einen Fehler, die Balken müssen anders sortiert werden. Glücklicherweise bekommt man bei pgfplots die Lösung gleich mitgeliefert. ;-) Der Code spuckt jetzt einen Skalierungsfaktor aus, der eingetragen werden muss, und zwar ist das `0.9952` in `0.9952*z \as \myz`. Ich habe es nicht geschafft, das zu automatisieren. (Die einzige Möglichkeit, die mir einfällt, wäre einen leeren plot in eine `\savebox` zu schustern, dort den Skalierungsfaktor zu berechnen und dann den richtigen Plot zu fahren. Aber das würde dazu führen, dass der Benutzer auch alles in dein Fake-Plot tut, oder dass ich ein kompliziertes Makro schreibe. Mir erscheint daher, dass das kleinste Übel ist, dass man den Wert nach dem Durchlauf einfach einträgt. Falls jemand einen besseren Vorschlag hat, würde ich den gerne hören, insbesondere wenn der jemand Feuersänger heisst. ;-) [1]: https://texwelt.de/wissen/upfiles/Screen_Shot_2018-06-05_at_8.03.23_PM.pnghttps://texwelt.de/wissen/upfiles/Screen_Shot_2018-06-07_at_1.07.15_PM.png
Klicke auf Einblenden/Ausblenden von Überarbeitungen 3
Bug behoben (Sortierung)

06 Jun '18, 05:27

Gel%C3%B6scht's gravatar image

Gelöscht
(ausgesetzt)

Hier ist ein Vorschlag. pgfplots hat die Möglichkeit, in einem scatter plot Würfel zu zeichnen und man kann die Längen der Kanten ändern. [![alt text][1]][1] \documentclass[tikz,border=3.14pt]{standalone} \usepackage{pgfplots} \usepackage{pgfplotstable} \pgfplotsset{compat=1.15} \begin{document} \pgfplotstableread[col sep=comma,header=true]{% x,y,color,myvalue 2,3,1,100 4,3,2,3 2,7,3,0.75 7,7,4,45 8,5,2,3 2,5,1,10 4,-4,2,1 4,1,3,75 5,-1,4,4 5,2,2,3 1,-2,1,10 2,5,2,5 3,-8,3,75 4,5,4,42 7,-2,2,2 }{\datatable} % \pgfplotstablesort[col sep=comma,header=true]\resulttable{\datatable} \begin{tikzpicture}%[x={(0.866cm,-0.5cm)},y={(0.866cm,0.5cm)},z={(0cm,1 cm)}] \pgfplotsset{set layers} \begin{axis}[% from section 4.6.4 of the pgfplotsmanual view={120}{40}, width=320pt, height=280pt, z buffer=sort, buffer=none, xmin=-1,xmax=8, ymin=-10,ymax=8, zmin=0,zmax=200, enlargelimits=upper, ztick={0,100,200}, zticklabels={0,50,100}, % hier muss man etwas tricksen here one has to "cheat" xtick=data, extra tick style={grid=major}, ytick=data, grid=minor, xlabel={$x$}, ylabel={$y$}, zlabel={$z$}, minor tick num=1, point meta=explicit, colormap name=viridis, scatter/use mapped color={ draw=mapped color,fill=mapped color!70}, ] \addplot3 [visualization depends on={z \as \myz}, scatter/@pre marker code/.append style={/pgfplots/cube/size z=\myz},% scatter,only marks, mark=cube*,mark size=5,opacity=0.6] size=5] table[x expr={\thisrow{x}},y expr={\thisrow{y}},z expr={\thisrow{myvalue}}, meta expr={\thisrow{color}} ] \datatable; \resulttable; \end{axis} \end{tikzpicture} \end{document} [![alt text][1]][1] **UPDATE**: Mein ursprünglicher Code hatte einen Fehler, die Balken müssen anders sortiert werden. Glücklicherweise bekommt man bei pgfplots die Lösung gleich mitgeliefert. ;-) [1]: https://texwelt.de/wissen/upfiles/Screen_Shot_2018-04-08_at_6.38.54_AM.pnghttps://texwelt.de/wissen/upfiles/Screen_Shot_2018-06-05_at_8.03.23_PM.png
Klicke auf Einblenden/Ausblenden von Überarbeitungen 2
Ich hatte mich mit der Länge der vertikalen Kante vertan.

08 Apr '18, 15:59

Gel%C3%B6scht's gravatar image

Gelöscht
(ausgesetzt)

Klicke auf Einblenden/Ausblenden von Überarbeitungen 1

08 Apr '18, 06:50

Gel%C3%B6scht's gravatar image

Gelöscht
(ausgesetzt)

Willkommen, erstes Mal hier? Schau mal unter FAQ!

×