2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00

added 3d manhattan bar plot

This commit is contained in:
Martin Thoma 2013-02-07 12:19:11 +01:00
parent a9a8042403
commit 6695d02301
5 changed files with 158 additions and 0 deletions

View file

@ -0,0 +1,44 @@
\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}
\usepackage{pgfplots}
\begin{document}
\begin{preview}
\begin{tikzpicture}
\begin{axis}[
view = {120}{35},% important to draw x,y in increasing order
xmin = 0,
ymin = 0,
xmax = 4,
ymax = 4,
zmin = 0,
unbounded coords = jump,
colormap={pos}{color(0cm)=(white); color(6cm)=(blue)}
]
\addplot3[surf,mark=none] coordinates {
(0,0,0.0) (0,0,0.0) (0,1,0.0) (0,1,0.0) (0,2,0.0) (0,2,0.0) (0,3,0.0) (0,3,0.0) (0,4,0.0) (0,4,0.0)
(0,0,0.0) (0,0,2) (0,1,2) (0,1,3) (0,2,3) (0,2,1) (0,3,1) (0,3,0) (0,4,0) (0,4,0.0) (1,0,0.0)
(1,0,2) (1,1,2) (1,1,3) (1,2,3) (1,2,1) (1,3,1) (1,3,0) (1,4,0) (1,4,0.0)
(1,0,0.0) (1,0,0) (1,1,0) (1,1,6) (1,2,6) (1,2,0) (1,3,0) (1,3,0) (1,4,0) (1,4,0.0) (2,0,0.0)
(2,0,0) (2,1,0) (2,1,6) (2,2,6) (2,2,0) (2,3,0) (2,3,0) (2,4,0) (2,4,0.0)
(2,0,0.0) (2,0,1) (2,1,1) (2,1,0) (2,2,0) (2,2,0) (2,3,0) (2,3,4) (2,4,4) (2,4,0.0) (3,0,0.0)
(3,0,1) (3,1,1) (3,1,0) (3,2,0) (3,2,0) (3,3,0) (3,3,4) (3,4,4) (3,4,0.0)
(3,0,0.0) (3,0,0) (3,1,0) (3,1,0) (3,2,0) (3,2,0) (3,3,0) (3,3,0) (3,4,0) (3,4,0.0) (4,0,0.0)
(4,0,0) (4,1,0) (4,1,0) (4,2,0) (4,2,0) (4,3,0) (4,3,0) (4,4,0) (4,4,0.0)
(4,0,0.0) (4,0,0.0) (4,1,0.0) (4,1,0.0) (4,2,0.0) (4,2,0.0) (4,3,0.0) (4,3,0.0) (4,4,0.0) (4,4,0.0)
};
\end{axis}
\end{tikzpicture}
\end{preview}
\end{document}

View file

@ -0,0 +1,37 @@
SOURCE = 3d-manhattan-bar-plot
DELAY = 80
DENSITY = 300
WIDTH = 500
make:
python getCoordinates.py
rm data
pdflatex $(SOURCE).tex -output-format=pdf
make clean
clean:
rm -rf $(TARGET) *.class *.html *.log *.aux *.data *.gnuplot
gif:
pdfcrop $(SOURCE).pdf
convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif
make clean
png:
make
make svg
inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png
transparentGif:
convert $(SOURCE).pdf -transparent white result.gif
make clean
svg:
make
#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
pdf2svg $(SOURCE).pdf $(SOURCE).svg
# Necessary, as pdf2svg does not always create valid svgs:
inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg
rsvg-convert -a -w $(WIDTH) -f svg $(SOURCE).svg -o $(SOURCE)2.svg
inkscape $(SOURCE)2.svg --export-plain-svg=$(SOURCE).svg
rm $(SOURCE)2.svg

View file

@ -0,0 +1,7 @@
This is from
http://tex.stackexchange.com/a/53754/5645
- an answer from [anton](http://tex.stackexchange.com/users/14063/anton)
and [Jake](http://tex.stackexchange.com/users/2552/jake)
The Python script got improved by Martin Thoma

View file

@ -0,0 +1,44 @@
def writeCoordinates(file, x, y, z):
file.write("(" + str(x) + "," + str(y) + "," + str(z) + ") ")
def createTex(x, y, z, output='3d-manhattan-bar-plot.tex'):
template = open('template.tpl', 'r').read()
make3dhistogram(x, y, z, 0.0, 'data')
data = open('data', 'r').read()
file = open(output, 'wb')
template = template.replace('[PLACE_PLOT_HERE]', data)
template = template.replace('[XMAX]', str(len(x)-1))
template = template.replace('[YMAX]', str(len(y)-1))
file.write(template)
def make3dhistogram(x, y, z, zmin, output):
file = open(output, 'wb')
i = 0
for j in range(len(y)):
writeCoordinates(file, x[i], y[j], zmin)
writeCoordinates(file, x[i], y[j], zmin)
file.write("\n\n")
for i in range(len(x)-1):
writeCoordinates(file, x[i], y[0], zmin)
for j in range(len(y)-1):
writeCoordinates(file, x[i], y[j], z[i][j])
writeCoordinates(file, x[i], y[j+1], z[i][j])
writeCoordinates(file, x[i], y[len(y)-1], zmin)
writeCoordinates(file, x[i+1], y[0], zmin)
file.write("\n\n")
for j in range(len(y)-1):
writeCoordinates(file, x[i+1], y[j], z[i][j])
writeCoordinates(file, x[i+1], y[j+1], z[i][j])
writeCoordinates(file, x[i+1], y[len(y)-1], zmin)
file.write("\n\n")
i = len(x)-1
for j in range(len(y)):
writeCoordinates(file, x[i], y[j], zmin)
writeCoordinates(file, x[i], y[j], zmin)
if __name__ == "__main__":
x = [0,1,2,3,4]
y = [0,1,2,3,4] # <- size of y
z = [[2,3,1,0], [0,6,0,0], [1,0,0,4], [0,0,0,0]]
createTex(x,y,z)

View file

@ -0,0 +1,26 @@
\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}
\usepackage{pgfplots}
\begin{document}
\begin{preview}
\begin{tikzpicture}
\begin{axis}[
view = {120}{35},% important to draw x,y in increasing order
xmin = 0,
ymin = 0,
xmax = [XMAX],
ymax = [YMAX],
zmin = 0,
unbounded coords = jump,
colormap={pos}{color(0cm)=(white); color(6cm)=(blue)}
]
\addplot3[surf,mark=none] coordinates {
[PLACE_PLOT_HERE]
};
\end{axis}
\end{tikzpicture}
\end{preview}
\end{document}