pgfplots 中 3D 条形图位置不正确

pgfplots 中 3D 条形图位置不正确

在此处输入图片描述 我想绘制一个像上面那样的三维条形图,但条形的位置不正确。我如何获得准确的位置?代码和输出如下所示。有人知道这个吗?提前感谢您的帮助!

    \documentclass[tikz,border=3.14pt]{standalone}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16}
\pgfkeys{/tikz/.cd,
cube top color/.store in=\CubeTopColor,cube top color=blue!60,
cube front color/.store in=\CubeFrontColor,cube front color=blue!30,
cube side color/.store in=\CubeSideColor,cube side color=blue!40,
3d cube color/.code={\colorlet{mycolor}{#1}%
\tikzset{cube top color=mycolor!60,cube front color=mycolor!30,
cube side color=mycolor!40,
draw=mycolor}}}

\makeatletter
\pgfdeclareplotmark{half cube*}
{%
\pgfplots@cube@gethalf@x
\let\pgfplots@cube@halfx=\pgfmathresult
\pgfplots@cube@gethalf@y
\let\pgfplots@cube@halfy=\pgfmathresult
\pgfplots@cube@gethalf@z
\let\pgfplots@cube@halfz=\pgfmathresult
\pgfmathparse{0*\pgfplots@cube@halfz}%
\let\pgfplots@cube@topz=\pgfmathresult
\pgfmathparse{-1*\pgfplots@cube@halfz}%
\let\pgfplots@cube@bottomz=\pgfmathresult%
\pgfplotsifaxissurfaceisforeground{0vv}
{%
\pgfsetfillcolor{\CubeFrontColor}
\pgfpathmoveto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathlineto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathclose
\pgfusepathqfillstroke}
{% 
\pgfsetfillcolor{\CubeFrontColor}
\pgfpathmoveto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathclose
\pgfusepathqfillstroke}%
\pgfplotsifaxissurfaceisforeground{v0v}
{%
\pgfsetfillcolor{\CubeSideColor}
\pgfpathmoveto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathlineto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathclose
\pgfusepathqfillstroke}
{% 
\pgfsetfillcolor{\CubeSideColor}
\pgfpathmoveto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathlineto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathclose
\pgfusepathqfillstroke}%
\pgfplotsifaxissurfaceisforeground{vv0}
{%
\pgfsetfillcolor{\CubeTopColor}
\pgfpathmoveto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathlineto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@bottomz}}%
\pgfpathclose
\pgfusepathqfillstroke}
{% 
\pgfsetfillcolor{\CubeTopColor}
\pgfpathmoveto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{-\pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{ \pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathlineto{\pgfplotsqpointxyz{ \pgfplots@cube@halfx}{-\pgfplots@cube@halfy}{\pgfplots@cube@topz}}%
\pgfpathclose
\pgfusepathqfillstroke
}%
}
\makeatother
\begin{document}
\begin{tikzpicture}[scale=1, transform shape]
\pgfmathsetmacro{\gconv}{63.85498}%<- you get told what you need to put here
\begin{axis}[
view={110}{20},
width=20cm,
height=20cm,
grid=major,
xmin=0,xmax=10.5,
ymin=0,ymax=20.5,
zmin=0,%zmax=10,
xtick={1.65,3.65,5.65,7.65,9.65},
xticklabels={
$B_{\alpha}NT_{66}$,
$B_{\alpha}NT_{55}$,
$B_{\alpha}NT_{44}$,
$B_{\alpha}NT_{33}$,
$B_{\alpha}NT_{22}$},
ytick={
1.25,
2.25,
3.25,
4.25,
5.25,
6.25,
7.25,
8.25,
9.25,
10.25,
11.25,
12.25,
13.25,
14.25,
15.25,
16.25,
17.25,
18.25
},
yticklabels={
{$PGO$},
{$^{m}M_{1}$},
{$R_{-\frac{1}{2}}$},
{$SCI$},
{$AG_{1}$},
{$ReZG_{1}$},
{$ReZG_{2}$},
{$RRR$},
{$RR$},
{$SK_{1}$},
{$SK$},
{$EM_{1}$},
{$SK_{2}$},
{$2SCI_{2}$},
{$NZ$},
{$G_{1}O$},
{$HM_{2}$},
{$3ReZG_{3}$}
},
ztick={1,2,3,4,5,6,7,8,9,10},
zticklabels={100,200,300,400,500,600,700,800,900,1000},
xlabel={$B_{\alpha}NT_{lq}$},
ylabel={Topological Indices},
%zlabel={},
axis equal,
]
\path let \p1=($(axis cs:0,0,1)-(axis cs:0,0,0)$) in 
\pgfextra{\pgfmathsetmacro{\conv}{2*\y1}
\ifx\gconv\conv
\typeout{z-scale\space good!}
\else
\typeout{Kindly\space consider\space setting\space the\space 
prefactor\space of\space z\space to\space \conv}
\fi     
};  

\pgfplotsset{3d bars/.style={only marks,scatter,mark=half cube*,mark size=0.6cm, 
3d cube color=#1,point meta=0,
,visualization depends on={\gconv*z \as \myz},
scatter/@pre marker code/.append style={/pgfplots/cube/size z=\myz},}}

\addplot3[3d bars=black]coordinates     {(0,0,9.988)(3,1,6.475)  (5,1,3.701) (7,1,1.667)(9,1,0.372)};
\addplot3[3d bars=yellow]coordinates    {(1,2,9.95)(3,2,6.364)(5,2,3.549) (7,2,1.505)(9,2,0.232)};
\addplot3[3d bars=magenta]coordinates   {(1,3,9.713)(3,3,6.413)(5,3,3.785)(7,3,1.83)(9,3,0.548)};
\addplot3[3d bars=green]coordinates     {(1,4,9.48)(3,4,6.8)(5,4,4.36)(7,4,2.76)(9,4,1.4)};
\addplot3[3d bars=orange]coordinates    {(1,5,9.34)(3,5,6.15)(5,5,3.613)(7,5,1.73)(9,5,0.5)};
\addplot3[3d bars=red]coordinates       {(1,6,9.34)(3,6,6.15)(5,6,3.613)(7,6,1.73) (9,6,0.5)};
\addplot3[3d bars=red]coordinates       {(1,7,8.97)(3,7,5.863)(5,7,3.4)(7,7,1.583) (9,7,0.41)};
\addplot3[3d bars=purple]coordinates    {(1,8,7.71)(3,8,5.5)(5,8,3.66)(7,8,2.19)(9,8,1.09)};
\addplot3[3d bars=violet]coordinates    {(1,9,6.908)(3,9,4.538)(5,9,2.655)(7,9,1.26) (9,9,0.353)};
\addplot3[3d bars=black]coordinates     {(1,10,5.568) (3,10,3.717)  (5,10,2.236) (7,10,1.123) (9,10,0.38)};
\addplot3[3d bars=yellow]coordinates    {(1,11,4.416)(3,11,2.933)(5,11,1.748) (7,11,0.863)(9,11,0.276)};
\addplot3[3d bars=magenta]coordinates   {(1,12,2.764)(3,12,1.843)(5,12,1.106)(7,12,0.553)(9,12,0.185)};
\addplot3[3d bars=green]coordinates     {(1,13,0.479)(3,13,0.333)(5,13,0.213)(7,13,0.12)(9,13,0.053)};
\addplot3[3d bars=orange]coordinates    {(1,14,0.381)(3,14,0.777)(5,14,0.481)(7,14,0.256)(9,14,0.1)};
\addplot3[3d bars=red]coordinates       {(1,15,0.366)(3,15,0.251)(5,15,0.158)(7,15,0.086) (9,15,0.036)};
\addplot3[3d bars=blue]coordinates      {(1,16,0.238)(3,16,0.165)(5,16,0.105)(7,16,0.059)(9,16,0.026)};
\addplot3[3d bars=purple]coordinates    {(1,17,0.118)(3,17,0.082)(5,17,0.052)(7,17,0.029)(9,17,0.013)};
\addplot3[3d bars=violet]coordinates    {(1,18,0.077)(3,18,0.054)(5,18,0.035)(7,18,0.02) (9,18,0.009)};

\end{axis}
\end{tikzpicture}
\end{document} 

在此处输入图片描述

相关内容