Je suis tombé sur un vieux topic qui donnait une macro pour faire des histogrammes en 3d, avec un paramètre et deux échelles (par evariste_G).
La macro
- Code: Tout sélectionner
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{xifthen}
\usetikzlibrary[arrows,fadings]
\newif\iffirstiteration
\newcounter{nb}
\newcommand{\barre}[6]
{ % n° colonne, largeur, hauteur, coefficient de profondeur, couleur, texte
\def\Ey{#3}
\pgfmathparse{(#1-1)*#2} \let\Ex\pgfmathresult
\pgfmathparse{#4*cos(-135)+\Ex} \let\Ax\pgfmathresult
\pgfmathparse{#4*sin(-135)+\Ey} \let\Ay\pgfmathresult
\pgfmathparse{\Ax+#2} \let\Bx\pgfmathresult
\pgfmathparse{\Ex+#2} \let\Fx\pgfmathresult
\pgfmathparse{\Ay-#3} \let\Cy\pgfmathresult
\filldraw[fill=#5,draw=black] (\Ax,\Ay) rectangle +(#2,-#3);
\filldraw[fill=#5!50,draw=black] (\Ax,\Ay) -- (\Ex,\Ey) -- (\Fx,\Ey) -- (\Bx,\Ay) -- cycle;
\filldraw[fill=#5!20,draw=black] (\Bx,\Ay) -- (\Fx,\Ey) -- (\Fx,0) -- (\Bx,\Cy) -- cycle;
\pgfmathparse{\Ax+#2/2} \let\texteB\pgfmathresult
\node[rotate=45,below left] at (\texteB,\Cy) {\begin{tiny}\textcolor{#5}{#6}\end{tiny}};
}
\newcommand{\repere}[3]
{ % xmax, ymax, profondeur max
\tikzfading[name=fade right,left color=transparent!0,right color=transparent!100]
\tikzfading[name=fade left,left color=transparent!100,right color=transparent!0]
\tikzfading[name=fade out,inner color=transparent!0,outer color=transparent!100]
\pgfmathparse{#3*cos(-135)} \let\X\pgfmathresult
\pgfmathparse{#3*sin(-135)} \let\Y\pgfmathresult
\pgfmathparse{4*#1/3} \let\XXr\pgfmathresult
\pgfmathparse{2*#1/3} \let\Xr\pgfmathresult
\pgfmathparse{\Y+#2-0.5} \let\ZZ\pgfmathresult
\pgfmathparse{#2-0.5} \let\YY\pgfmathresult
\pgfmathparse{#1-0.3} \let\XX\pgfmathresult
\pgfmathparse{\X+#1} \let\XXX\pgfmathresult
\pgfmathparse{#1/2} \let\xsh\pgfmathresult
\pgfmathparse{#3/2} \let\ysh\pgfmathresult
\fill [gray!50,path fading=fade out,fading transform={xshift=-0.75 cm,yshift=0.5 cm}] (0,0) -- (\X,\Y) .. controls (\Xr,-#3) and (\XXr,\Y) .. (1.85*#1,0.5) -- cycle;
\fill[white] (0,0) rectangle +(#1+1,\YY);
\fill[gray!50,path fading=fade right] (0,0) rectangle +(#1,\YY);
\fill[gray!50,path fading=fade left] (0,0) -- (0,\YY) -- (\X,\ZZ) -- (\X,\Y) -- cycle;
\draw[->,>=stealth'] (0,0) -- (#1,0);
\draw[->,>=stealth'] (0,0) -- (0,#2);
\draw[->,>=stealth'] (0,0) -- (\X,\Y);
\foreach \i in {1,2,...,\YY}
{
\pgfmathparse{(#3-0.2)*cos(-135)} \let\ZX\pgfmathresult
\pgfmathparse{(#3-0.2)*sin(-135)+\i} \let\ZY\pgfmathresult
\draw[dotted] (\ZX,\ZY) node[color=gray,left] {\begin{tiny}\i\end{tiny}} -- (0,\i) -- (\XX,\i) node[color=gray,right] {\begin{tiny}\i\end{tiny}};
}
}
\def\spacebar[#1]#2{% échelle en X, échelle en Y, paramètres
\begin{tikzpicture}[#1]
\firstiterationtrue
\def\xmaximum{0}
\setcounter{nb}{0}
\foreach \hauteur/\largeur/\coefprof/\couleur/\texte in {#2}
{
\ifx\largeur\empty\def\largeur{1}\fi
\ifx\coefprof\empty\def\coefprof{0.33}\fi
\iffirstiteration
\xdef\hauteurmax{\hauteur}
\xdef\coefprofmax{\coefprof}
\else
\ifnum\hauteurmax>\hauteur
\else
\xdef\hauteurmax{\hauteur}
\fi
\pgfmathmax{\coefprofmax}{\coefprof}\global\let\coefprofmax\pgfmathresult
\fi
\global\firstiterationfalse
\pgfmathparse{\largeur+\xmaximum}\global\let\xmaximum\pgfmathresult
}
\pgfmathparse{\xmaximum+1}\global\let\xmaximum\pgfmathresult
\pgfmathparse{\coefprofmax+0.66}\global\let\coefprofmax\pgfmathresult
\pgfmathparse{\hauteurmax+1}\global\let\hauteurmax\pgfmathresult
\repere{\xmaximum}{\hauteurmax}{\coefprofmax}
\foreach \hauteur/\largeur/\coefprof/\couleur/\texte in {#2}
{
\stepcounter{nb}
\ifx\largeur\empty\def\largeur{1}\fi
\ifx\coefprof\empty\def\coefprof{0.33}\fi
\ifx\couleur\empty\def\couleur{blue}\fi
\barre{\thenb}{\largeur}{\hauteur}{\coefprof}{\couleur}{\texte}
}
\end{tikzpicture}
}
\begin{document}
% Synthaxe : \spacebar{effectif, largeur de la colonne, profondeur de la colonne, couleur, caractère observé}
\spacebar[scale=1]{
3/1/0.66/green/Bus,%
5/1/0.33/red/Vélo,%
2/1/0.66/purple/A pieds,%
6/1/0.33/brown/Voiture,%
4/1/0.66/magenta/Hélicoptère}
\end{document}
donne ceci:
Mon problème est que je souhaite pouvoir avoir deux paramètres (largeur et profondeur), et une seule échelle (hauteur) pour pouvoir inscrire parfaitement mes données pour mon TPE … et je suis une quiche en programmation latex, pareil pour tikz, puisque j'ai l'habitude d'importer depuis geogebra, ce qui est impossible ici. Des gens plus expérimentés auraient-ils la solution pour moi ?