我正在寻找具有维度层次结构的 OLAP 多维数据集的 TikZ 图片示例。 大致类似于此多维数据集:
我知道如何根据以下信息绘制立方体使用 TikZ 绘制 3D 立方体的最简单方法是什么?和数独 3D 立方体示例。但我不知道如何很好地表达维度的层次结构,例如使用树 tikz 库。
答案1
这不完全是对你问题的回答,因为我不使用“树”库,但如果你制作一个宏,就可以简化代码:我没有放“发货日期”和“产品”,因为在主平面上工作很容易
\documentclass[10pt]{article}
\usepackage{tikz}
\newcommand\pgfmathsinandcos[3]{%
\pgfmathsetmacro#1{sin(#3)}
\pgfmathsetmacro#2{cos(#3)}}
\begin{document}
\pgfmathsetmacro\angFuite{30}
\pgfmathsetmacro\coeffReduc{0.5}
\begin{tikzpicture}[scale=.75]
\pgfmathsinandcos\sint\cost{\angFuite} %
\draw (0,0)--(8,0)--(8,8)--(0,8)--(0,0)
(4,0)--(4,8) (0,4)--(8,4);
\path[coordinate] (8,4) coordinate (A);
\tikzset{current plane/.estyle={%
cm={1,0,\coeffReduc*\cost,\coeffReduc*\sint,(0,0)}}}
\begin{scope}[current plane]
\draw (8,0)--(8,8);
\end{scope}
\tikzset{current plane/.estyle={%
cm={1,0,\coeffReduc*\cost,\coeffReduc*\sint,(0,8)}}}
\begin{scope}[current plane]
\draw (4,0)--(4,8) (0,4)--(8,4) (4,0)--(4,8);
\draw (8,0)--(8,8)
(0,8)--(0,0)
(-3.5,0)--(-4,0)--(-4,8)--(-3.5,8) node[right] {Los Angeles};
\node[right] at (-3.5,0){New York};
\draw (-4,4)--(-4.5,4) node [left]{\textbf{location}};
\path[coordinate] (8,4) coordinate (C);
\end{scope}
\tikzset{current plane/.estyle={%
cm={1,0,0,1,(8*\coeffReduc*\cost,8*\coeffReduc*\sint)}}}
\begin{scope}[current plane]
\draw (8,0)--(8,8)--(0,8);
\path[coordinate] (8,4) coordinate (B);
\end{scope}
\draw (A)--(B);
\draw (C)--++(0,-8);
\end{tikzpicture}
\end{document}
答案2
这是我玩了一下这个tikz-3dplot
包之后得到的结果(我很累,所以我的代码有点蛮力懒惰):
\documentclass{article}
\usepackage[]{tikz}
\usepackage[]{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{70}{110} %set the viewing angle
\begin{tikzpicture}[tdplot_main_coords,every node/.style={font=\tiny,outer sep=0pt,inner sep=2pt},scale=1.3]
%front
\draw[thick](0,0,0)--++(0,2,0)--++(0,0,2)--++(0,-2,0)--cycle;
\draw[] (0,0,0)--++(0,1,0)--++(0,0,1)--++(0,-1,0)--cycle;
\draw[] (0,1,1)--++(0,1,0)--++(0,0,1)--++(0,-1,0)--cycle;
%side
\draw[thick]( 0,2,0)--++(-2,0,0)--++(0,0,2)--++(2,0,0)--cycle;
\draw[] ( 0,2,0)--++(-1,0,0)--++(0,0,1)--++(1,0,0)--cycle;
\draw[] (-1,2,1)--++(-1,0,0)--++(0,0,1)--++(1,0,0)--cycle;
%top
\draw[thick]( 0,0,2)--++(0,2,0)--++(-2,0,0)--++(0,-2,0)--cycle;
\draw[] ( 0,0,2)--++(0,1,0)--++(-1,0,0)--++(0,-1,0)--cycle;
\draw[] (-1,1,2)--++(0,1,0)--++(-1,0,0)--++(0,-1,0)--cycle;
\def\A{1}
\def\B{1}
\draw(-0.1,0,2)++(0,-\A,0)--node[above,sloped,at start]{Los Angeles}++(0,-\B,0)--++(-1.8,0,0)--node[below,sloped]{New York}++(0,\B,0)coordinate(NY);
\draw(-1,-\A-\B,2)--node[left,sloped,at end]{\bf location}++(0,-0.3,0);
\draw(0,0,0.1)++(0,-\A,0)--node[above,sloped,near start]{Tennis racquets}++(0,-\B,0)--++(0,0,1.8)--node[below,sloped,at end]{Soccer balls}++(0,\B,0);
\draw(0,-\A-\B,1)--node[left,near end,sloped]{\bf product}++(0,-0.3,0);
\def\B{1.3}
\def\A{1.2}
\draw(\A,0.1,0)--node[below,sloped,at start]{January}++(\B,0,0)--++(0,1.8,0)--node[above,sloped,near end]{February}++(-\B,0,0); \draw(\A+\B,1,0)--++(0.3,0,0)coordinate(SD);
\draw[draw=none](SD)--node[sloped,below]{\bf Shipping Date}++(0,0.1,0);
\end{tikzpicture}
\end{document}
文本可读性
好的,这个例子没有任何倾斜的文本:\documentclass{article} \usepackage[]{tikz} \usepackage[]{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{76}{103}
\begin{tikzpicture}[tdplot_main_coords,every node/.style={font=\tiny,outer sep=0pt,inner sep=2pt},scale=1.3]
%front
\draw[thick](0,0,0)--++(0,2,0)--++(0,0,2)--++(0,-2,0)--cycle;
\draw[] (0,0,0)--++(0,1,0)--++(0,0,1)--++(0,-1,0)--cycle;
\draw[] (0,1,1)--++(0,1,0)--++(0,0,1)--++(0,-1,0)--cycle;
%side
\draw[thick]( 0,2,0)--++(-2,0,0)--++(0,0,2)--++(2,0,0)--cycle;
\draw[] ( 0,2,0)--++(-1,0,0)--++(0,0,1)--++(1,0,0)--cycle;
\draw[] (-1,2,1)--++(-1,0,0)--++(0,0,1)--++(1,0,0)--cycle;
%top
\draw[thick]( 0,0,2)--++(0,2,0)--++(-2,0,0)--++(0,-2,0)--cycle;
\draw[] ( 0,0,2)--++(0,1,0)--++(-1,0,0)--++(0,-1,0)--cycle;
\draw[] (-1,1,2)--++(0,1,0)--++(-1,0,0)--++(0,-1,0)--cycle;
\def\A{0.5}
\def\B{1.3}
\draw(-0.1,0,2)++(0,-\A,0)--node[above,near start]{Los Angeles}++(0,-\B,0)--++(-1.8,0,0)--node[below,near end]{New York}++(0,\B,0)coordinate(NY);
\draw(-1,-\A-\B,2)--++(0,-0.3,0)node[left,anchor=south east]{\bf location};
\draw(0,0,0.1)++(0,-\A,0)--node[above,near start]{Tennis racquets}++(0,-\B,0)--++(0,0,1.8)--node[below,near end]{Soccer balls}++(0,\B,0);
\draw(0,-\A-\B,1)--++(0,-0.3,0)node[left,anchor=east]{\bf product};
\def\B{1.3}
\def\A{1.2}
\draw(\A,0.1,0)--node[right,near start]{January}++(\B,0,0)--++(0,1.8,0)--node[left,near end]{February}++(-\B,0,0);
\draw(\A+\B,1,0)--++(0.3,0,0)node[below left]{\bf Shipping Date};
\end{tikzpicture}
\end{document}