How to plot trinomial distribution in tikz?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite












I am trying to plot a 3d probability mass function like below (probability histogram for trinomial distribution). Could not find anything helpful online for 3D discrete plotting like below given a function (joint pmf). Kindly help.



enter image description here



Function:
enter image description here



The pic is from the book here Page 132. Probability and Statistical Inference By Hoggs et al.



Update:

Thanks to @marmot, I have managed to bring to a level as below. Yet to understand his code fully though.



enter image description here










share|improve this question



















  • 1




    Could you please add the function in form of a typed text?
    – marmot
    2 hours ago






  • 1




    I think there are a lot of parameters. In order to plot you have to pick particular values, I think.
    – manooooh
    2 hours ago










  • oh sorry marmot just saw this comment now.
    – Paari Vendhan
    15 mins ago














up vote
4
down vote

favorite












I am trying to plot a 3d probability mass function like below (probability histogram for trinomial distribution). Could not find anything helpful online for 3D discrete plotting like below given a function (joint pmf). Kindly help.



enter image description here



Function:
enter image description here



The pic is from the book here Page 132. Probability and Statistical Inference By Hoggs et al.



Update:

Thanks to @marmot, I have managed to bring to a level as below. Yet to understand his code fully though.



enter image description here










share|improve this question



















  • 1




    Could you please add the function in form of a typed text?
    – marmot
    2 hours ago






  • 1




    I think there are a lot of parameters. In order to plot you have to pick particular values, I think.
    – manooooh
    2 hours ago










  • oh sorry marmot just saw this comment now.
    – Paari Vendhan
    15 mins ago












up vote
4
down vote

favorite









up vote
4
down vote

favorite











I am trying to plot a 3d probability mass function like below (probability histogram for trinomial distribution). Could not find anything helpful online for 3D discrete plotting like below given a function (joint pmf). Kindly help.



enter image description here



Function:
enter image description here



The pic is from the book here Page 132. Probability and Statistical Inference By Hoggs et al.



Update:

Thanks to @marmot, I have managed to bring to a level as below. Yet to understand his code fully though.



enter image description here










share|improve this question















I am trying to plot a 3d probability mass function like below (probability histogram for trinomial distribution). Could not find anything helpful online for 3D discrete plotting like below given a function (joint pmf). Kindly help.



enter image description here



Function:
enter image description here



The pic is from the book here Page 132. Probability and Statistical Inference By Hoggs et al.



Update:

Thanks to @marmot, I have managed to bring to a level as below. Yet to understand his code fully though.



enter image description here







pgfplots pgfplotstable 3d bar-chart tikz-3dplot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 12 mins ago

























asked 2 hours ago









Paari Vendhan

1157




1157







  • 1




    Could you please add the function in form of a typed text?
    – marmot
    2 hours ago






  • 1




    I think there are a lot of parameters. In order to plot you have to pick particular values, I think.
    – manooooh
    2 hours ago










  • oh sorry marmot just saw this comment now.
    – Paari Vendhan
    15 mins ago












  • 1




    Could you please add the function in form of a typed text?
    – marmot
    2 hours ago






  • 1




    I think there are a lot of parameters. In order to plot you have to pick particular values, I think.
    – manooooh
    2 hours ago










  • oh sorry marmot just saw this comment now.
    – Paari Vendhan
    15 mins ago







1




1




Could you please add the function in form of a typed text?
– marmot
2 hours ago




Could you please add the function in form of a typed text?
– marmot
2 hours ago




1




1




I think there are a lot of parameters. In order to plot you have to pick particular values, I think.
– manooooh
2 hours ago




I think there are a lot of parameters. In order to plot you have to pick particular values, I think.
– manooooh
2 hours ago












oh sorry marmot just saw this comment now.
– Paari Vendhan
15 mins ago




oh sorry marmot just saw this comment now.
– Paari Vendhan
15 mins ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote













Here is a proposal (1st EDIT: resolved dimension too large problems; 2nd EDIT: followed @AndréC's excellent suggestion to slightly redefine the cube plot mark.):



documentclass[tikz,border=3.14pt]standalone
usetikzlibrarycalc
usepackagepgfplots
pgfplotssetcompat=1.16
pgfkeys/tikz/.cd,
cube top color/.store in=CubeTopColor,
cube top color=blue!20

makeatletter
pgfdeclareplotmarkmy cube*
%
pgfplots@cube@gethalf@x
letpgfplots@cube@halfx=pgfmathresult
pgfplots@cube@gethalf@y
letpgfplots@cube@halfy=pgfmathresult
pgfplots@cube@gethalf@z
letpgfplots@cube@halfz=pgfmathresult
%
pgfplotsifaxissurfaceisforeground0vv%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfpathmovetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfplotsifaxissurfaceisforegroundv0v%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfplotsifaxissurfaceisforegroundvv0%
pgfsetfillcolorCubeTopColor
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfsetfillcolorCubeTopColor
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%

makeatother

begindocument
pgfmathsetmacrogconv32.63245
% from https://tex.stackexchange.com/a/435234/121799
begintikzpicture[declare function=% (0.00001*n!/(0.01*x!*0.01*y!*0.01*(n-x-y)!))*
f(x,y,px,py,n)=(0.00001*n!/(0.01*x!*0.01*y!*0.01*(n-x-y)!))*pow(px,x)*pow(py,y)*pow(1-px-py,n-x-y);] %
pgfplotssetset layers
beginaxis[% from section 4.6.4 of the pgfplotsmanual
view=4040,
%x dir=reverse,
%y dir=reverse,
width=320pt,
height=280pt,
mesh,
%mesh/ordering=x varies,
z buffer=auto,%reverse xy seq,
xmin=-0.5,xmax=5.5,
ymin=-0.5,ymax=5.5,
zmin=0,zmax=6,
enlargelimits=upper,
%ztick=0,1000,2000,
%zticklabels=0,500,1000, % 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=0,...,5,xtick=0,...,5,
grid=minor,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
minor tick num=1,
point meta max=20,
point meta min=0,
colormap=blueblackcolor=(black) color=(blue),
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
pgfextrapgfmathsetmacroconv2*y1
ifxgconvconv
typeoutz-scalespace good!
else
typeoutKindlyspace considerspace settingspace thespace
prefactorspace ofspace zspace tospace conv
fi
;
path let p1=($(axis cs:1,0,0)-(axis cs:0,0,0)$) in
pgfextrapgfmathsetmacroconvxveclen(x1,y1)
typeoutOnespace unitspace inspace xspace
directionspace isspaceconvx pt
;
path let p1=($(axis cs:0,1,0)-(axis cs:0,0,0)$) in
pgfextrapgfmathsetmacroconvyveclen(x1,y1)
typeoutOnespace unitspace inspace yspace
directionspace isspaceconvy pt
;
addplot3 [cube top color=blue!40,point meta=12,visualization depends on=
gconv*z as myz, % you'll get told how to adjust the prefactor
scatter/@pre marker code/.append style=/pgfplots/cube/size z=myz,%
scatter/@pre marker code/.append style=/pgfplots/cube/size x=24.3018pt,%
scatter/@pre marker code/.append style=/pgfplots/cube/size y=21.71275pt,%
scatter,only marks,
mark=my cube*,mark size=5,opacity=1,domain=0:5,domain y=0:5,samples=6,samples y=6]
f(x,y,0.2,0.4,5);
endaxis
endtikzpicture
enddocument


enter image description here






share|improve this answer






















  • It would be much prettier if the sides were clearer than the upper faces.
    – AndréC
    1 hour ago










  • @AndréC What do you mean by clearer?
    – marmot
    1 hour ago






  • 1




    @marmot I think OP meant lighter shade on the top surface as shown in question.
    – nidhin
    1 hour ago






  • 1




    @AndréC Better now? The top color is set via a key, and the other color via the color map. Thanks for your great suggestion!
    – marmot
    13 mins ago






  • 1




    Ha Ha.. nice tutorial :D. @AndréC check it out.
    – Paari Vendhan
    5 mins ago










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f457226%2fhow-to-plot-trinomial-distribution-in-tikz%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote













Here is a proposal (1st EDIT: resolved dimension too large problems; 2nd EDIT: followed @AndréC's excellent suggestion to slightly redefine the cube plot mark.):



documentclass[tikz,border=3.14pt]standalone
usetikzlibrarycalc
usepackagepgfplots
pgfplotssetcompat=1.16
pgfkeys/tikz/.cd,
cube top color/.store in=CubeTopColor,
cube top color=blue!20

makeatletter
pgfdeclareplotmarkmy cube*
%
pgfplots@cube@gethalf@x
letpgfplots@cube@halfx=pgfmathresult
pgfplots@cube@gethalf@y
letpgfplots@cube@halfy=pgfmathresult
pgfplots@cube@gethalf@z
letpgfplots@cube@halfz=pgfmathresult
%
pgfplotsifaxissurfaceisforeground0vv%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfpathmovetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfplotsifaxissurfaceisforegroundv0v%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfplotsifaxissurfaceisforegroundvv0%
pgfsetfillcolorCubeTopColor
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfsetfillcolorCubeTopColor
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%

makeatother

begindocument
pgfmathsetmacrogconv32.63245
% from https://tex.stackexchange.com/a/435234/121799
begintikzpicture[declare function=% (0.00001*n!/(0.01*x!*0.01*y!*0.01*(n-x-y)!))*
f(x,y,px,py,n)=(0.00001*n!/(0.01*x!*0.01*y!*0.01*(n-x-y)!))*pow(px,x)*pow(py,y)*pow(1-px-py,n-x-y);] %
pgfplotssetset layers
beginaxis[% from section 4.6.4 of the pgfplotsmanual
view=4040,
%x dir=reverse,
%y dir=reverse,
width=320pt,
height=280pt,
mesh,
%mesh/ordering=x varies,
z buffer=auto,%reverse xy seq,
xmin=-0.5,xmax=5.5,
ymin=-0.5,ymax=5.5,
zmin=0,zmax=6,
enlargelimits=upper,
%ztick=0,1000,2000,
%zticklabels=0,500,1000, % 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=0,...,5,xtick=0,...,5,
grid=minor,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
minor tick num=1,
point meta max=20,
point meta min=0,
colormap=blueblackcolor=(black) color=(blue),
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
pgfextrapgfmathsetmacroconv2*y1
ifxgconvconv
typeoutz-scalespace good!
else
typeoutKindlyspace considerspace settingspace thespace
prefactorspace ofspace zspace tospace conv
fi
;
path let p1=($(axis cs:1,0,0)-(axis cs:0,0,0)$) in
pgfextrapgfmathsetmacroconvxveclen(x1,y1)
typeoutOnespace unitspace inspace xspace
directionspace isspaceconvx pt
;
path let p1=($(axis cs:0,1,0)-(axis cs:0,0,0)$) in
pgfextrapgfmathsetmacroconvyveclen(x1,y1)
typeoutOnespace unitspace inspace yspace
directionspace isspaceconvy pt
;
addplot3 [cube top color=blue!40,point meta=12,visualization depends on=
gconv*z as myz, % you'll get told how to adjust the prefactor
scatter/@pre marker code/.append style=/pgfplots/cube/size z=myz,%
scatter/@pre marker code/.append style=/pgfplots/cube/size x=24.3018pt,%
scatter/@pre marker code/.append style=/pgfplots/cube/size y=21.71275pt,%
scatter,only marks,
mark=my cube*,mark size=5,opacity=1,domain=0:5,domain y=0:5,samples=6,samples y=6]
f(x,y,0.2,0.4,5);
endaxis
endtikzpicture
enddocument


enter image description here






share|improve this answer






















  • It would be much prettier if the sides were clearer than the upper faces.
    – AndréC
    1 hour ago










  • @AndréC What do you mean by clearer?
    – marmot
    1 hour ago






  • 1




    @marmot I think OP meant lighter shade on the top surface as shown in question.
    – nidhin
    1 hour ago






  • 1




    @AndréC Better now? The top color is set via a key, and the other color via the color map. Thanks for your great suggestion!
    – marmot
    13 mins ago






  • 1




    Ha Ha.. nice tutorial :D. @AndréC check it out.
    – Paari Vendhan
    5 mins ago














up vote
3
down vote













Here is a proposal (1st EDIT: resolved dimension too large problems; 2nd EDIT: followed @AndréC's excellent suggestion to slightly redefine the cube plot mark.):



documentclass[tikz,border=3.14pt]standalone
usetikzlibrarycalc
usepackagepgfplots
pgfplotssetcompat=1.16
pgfkeys/tikz/.cd,
cube top color/.store in=CubeTopColor,
cube top color=blue!20

makeatletter
pgfdeclareplotmarkmy cube*
%
pgfplots@cube@gethalf@x
letpgfplots@cube@halfx=pgfmathresult
pgfplots@cube@gethalf@y
letpgfplots@cube@halfy=pgfmathresult
pgfplots@cube@gethalf@z
letpgfplots@cube@halfz=pgfmathresult
%
pgfplotsifaxissurfaceisforeground0vv%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfpathmovetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfplotsifaxissurfaceisforegroundv0v%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfplotsifaxissurfaceisforegroundvv0%
pgfsetfillcolorCubeTopColor
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfsetfillcolorCubeTopColor
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%

makeatother

begindocument
pgfmathsetmacrogconv32.63245
% from https://tex.stackexchange.com/a/435234/121799
begintikzpicture[declare function=% (0.00001*n!/(0.01*x!*0.01*y!*0.01*(n-x-y)!))*
f(x,y,px,py,n)=(0.00001*n!/(0.01*x!*0.01*y!*0.01*(n-x-y)!))*pow(px,x)*pow(py,y)*pow(1-px-py,n-x-y);] %
pgfplotssetset layers
beginaxis[% from section 4.6.4 of the pgfplotsmanual
view=4040,
%x dir=reverse,
%y dir=reverse,
width=320pt,
height=280pt,
mesh,
%mesh/ordering=x varies,
z buffer=auto,%reverse xy seq,
xmin=-0.5,xmax=5.5,
ymin=-0.5,ymax=5.5,
zmin=0,zmax=6,
enlargelimits=upper,
%ztick=0,1000,2000,
%zticklabels=0,500,1000, % 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=0,...,5,xtick=0,...,5,
grid=minor,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
minor tick num=1,
point meta max=20,
point meta min=0,
colormap=blueblackcolor=(black) color=(blue),
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
pgfextrapgfmathsetmacroconv2*y1
ifxgconvconv
typeoutz-scalespace good!
else
typeoutKindlyspace considerspace settingspace thespace
prefactorspace ofspace zspace tospace conv
fi
;
path let p1=($(axis cs:1,0,0)-(axis cs:0,0,0)$) in
pgfextrapgfmathsetmacroconvxveclen(x1,y1)
typeoutOnespace unitspace inspace xspace
directionspace isspaceconvx pt
;
path let p1=($(axis cs:0,1,0)-(axis cs:0,0,0)$) in
pgfextrapgfmathsetmacroconvyveclen(x1,y1)
typeoutOnespace unitspace inspace yspace
directionspace isspaceconvy pt
;
addplot3 [cube top color=blue!40,point meta=12,visualization depends on=
gconv*z as myz, % you'll get told how to adjust the prefactor
scatter/@pre marker code/.append style=/pgfplots/cube/size z=myz,%
scatter/@pre marker code/.append style=/pgfplots/cube/size x=24.3018pt,%
scatter/@pre marker code/.append style=/pgfplots/cube/size y=21.71275pt,%
scatter,only marks,
mark=my cube*,mark size=5,opacity=1,domain=0:5,domain y=0:5,samples=6,samples y=6]
f(x,y,0.2,0.4,5);
endaxis
endtikzpicture
enddocument


enter image description here






share|improve this answer






















  • It would be much prettier if the sides were clearer than the upper faces.
    – AndréC
    1 hour ago










  • @AndréC What do you mean by clearer?
    – marmot
    1 hour ago






  • 1




    @marmot I think OP meant lighter shade on the top surface as shown in question.
    – nidhin
    1 hour ago






  • 1




    @AndréC Better now? The top color is set via a key, and the other color via the color map. Thanks for your great suggestion!
    – marmot
    13 mins ago






  • 1




    Ha Ha.. nice tutorial :D. @AndréC check it out.
    – Paari Vendhan
    5 mins ago












up vote
3
down vote










up vote
3
down vote









Here is a proposal (1st EDIT: resolved dimension too large problems; 2nd EDIT: followed @AndréC's excellent suggestion to slightly redefine the cube plot mark.):



documentclass[tikz,border=3.14pt]standalone
usetikzlibrarycalc
usepackagepgfplots
pgfplotssetcompat=1.16
pgfkeys/tikz/.cd,
cube top color/.store in=CubeTopColor,
cube top color=blue!20

makeatletter
pgfdeclareplotmarkmy cube*
%
pgfplots@cube@gethalf@x
letpgfplots@cube@halfx=pgfmathresult
pgfplots@cube@gethalf@y
letpgfplots@cube@halfy=pgfmathresult
pgfplots@cube@gethalf@z
letpgfplots@cube@halfz=pgfmathresult
%
pgfplotsifaxissurfaceisforeground0vv%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfpathmovetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfplotsifaxissurfaceisforegroundv0v%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfplotsifaxissurfaceisforegroundvv0%
pgfsetfillcolorCubeTopColor
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfsetfillcolorCubeTopColor
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%

makeatother

begindocument
pgfmathsetmacrogconv32.63245
% from https://tex.stackexchange.com/a/435234/121799
begintikzpicture[declare function=% (0.00001*n!/(0.01*x!*0.01*y!*0.01*(n-x-y)!))*
f(x,y,px,py,n)=(0.00001*n!/(0.01*x!*0.01*y!*0.01*(n-x-y)!))*pow(px,x)*pow(py,y)*pow(1-px-py,n-x-y);] %
pgfplotssetset layers
beginaxis[% from section 4.6.4 of the pgfplotsmanual
view=4040,
%x dir=reverse,
%y dir=reverse,
width=320pt,
height=280pt,
mesh,
%mesh/ordering=x varies,
z buffer=auto,%reverse xy seq,
xmin=-0.5,xmax=5.5,
ymin=-0.5,ymax=5.5,
zmin=0,zmax=6,
enlargelimits=upper,
%ztick=0,1000,2000,
%zticklabels=0,500,1000, % 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=0,...,5,xtick=0,...,5,
grid=minor,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
minor tick num=1,
point meta max=20,
point meta min=0,
colormap=blueblackcolor=(black) color=(blue),
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
pgfextrapgfmathsetmacroconv2*y1
ifxgconvconv
typeoutz-scalespace good!
else
typeoutKindlyspace considerspace settingspace thespace
prefactorspace ofspace zspace tospace conv
fi
;
path let p1=($(axis cs:1,0,0)-(axis cs:0,0,0)$) in
pgfextrapgfmathsetmacroconvxveclen(x1,y1)
typeoutOnespace unitspace inspace xspace
directionspace isspaceconvx pt
;
path let p1=($(axis cs:0,1,0)-(axis cs:0,0,0)$) in
pgfextrapgfmathsetmacroconvyveclen(x1,y1)
typeoutOnespace unitspace inspace yspace
directionspace isspaceconvy pt
;
addplot3 [cube top color=blue!40,point meta=12,visualization depends on=
gconv*z as myz, % you'll get told how to adjust the prefactor
scatter/@pre marker code/.append style=/pgfplots/cube/size z=myz,%
scatter/@pre marker code/.append style=/pgfplots/cube/size x=24.3018pt,%
scatter/@pre marker code/.append style=/pgfplots/cube/size y=21.71275pt,%
scatter,only marks,
mark=my cube*,mark size=5,opacity=1,domain=0:5,domain y=0:5,samples=6,samples y=6]
f(x,y,0.2,0.4,5);
endaxis
endtikzpicture
enddocument


enter image description here






share|improve this answer














Here is a proposal (1st EDIT: resolved dimension too large problems; 2nd EDIT: followed @AndréC's excellent suggestion to slightly redefine the cube plot mark.):



documentclass[tikz,border=3.14pt]standalone
usetikzlibrarycalc
usepackagepgfplots
pgfplotssetcompat=1.16
pgfkeys/tikz/.cd,
cube top color/.store in=CubeTopColor,
cube top color=blue!20

makeatletter
pgfdeclareplotmarkmy cube*
%
pgfplots@cube@gethalf@x
letpgfplots@cube@halfx=pgfmathresult
pgfplots@cube@gethalf@y
letpgfplots@cube@halfy=pgfmathresult
pgfplots@cube@gethalf@z
letpgfplots@cube@halfz=pgfmathresult
%
pgfplotsifaxissurfaceisforeground0vv%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfpathmovetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfplotsifaxissurfaceisforegroundv0v%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfplotsifaxissurfaceisforegroundvv0%
pgfsetfillcolorCubeTopColor
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy-pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%
pgfsetfillcolorCubeTopColor
pgfpathmovetopgfplotsqpointxyz-pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz-pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathlinetopgfplotsqpointxyz pgfplots@cube@halfx-pgfplots@cube@halfy pgfplots@cube@halfz%
pgfpathclose
pgfusepathqfillstroke
%

makeatother

begindocument
pgfmathsetmacrogconv32.63245
% from https://tex.stackexchange.com/a/435234/121799
begintikzpicture[declare function=% (0.00001*n!/(0.01*x!*0.01*y!*0.01*(n-x-y)!))*
f(x,y,px,py,n)=(0.00001*n!/(0.01*x!*0.01*y!*0.01*(n-x-y)!))*pow(px,x)*pow(py,y)*pow(1-px-py,n-x-y);] %
pgfplotssetset layers
beginaxis[% from section 4.6.4 of the pgfplotsmanual
view=4040,
%x dir=reverse,
%y dir=reverse,
width=320pt,
height=280pt,
mesh,
%mesh/ordering=x varies,
z buffer=auto,%reverse xy seq,
xmin=-0.5,xmax=5.5,
ymin=-0.5,ymax=5.5,
zmin=0,zmax=6,
enlargelimits=upper,
%ztick=0,1000,2000,
%zticklabels=0,500,1000, % 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=0,...,5,xtick=0,...,5,
grid=minor,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
minor tick num=1,
point meta max=20,
point meta min=0,
colormap=blueblackcolor=(black) color=(blue),
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
pgfextrapgfmathsetmacroconv2*y1
ifxgconvconv
typeoutz-scalespace good!
else
typeoutKindlyspace considerspace settingspace thespace
prefactorspace ofspace zspace tospace conv
fi
;
path let p1=($(axis cs:1,0,0)-(axis cs:0,0,0)$) in
pgfextrapgfmathsetmacroconvxveclen(x1,y1)
typeoutOnespace unitspace inspace xspace
directionspace isspaceconvx pt
;
path let p1=($(axis cs:0,1,0)-(axis cs:0,0,0)$) in
pgfextrapgfmathsetmacroconvyveclen(x1,y1)
typeoutOnespace unitspace inspace yspace
directionspace isspaceconvy pt
;
addplot3 [cube top color=blue!40,point meta=12,visualization depends on=
gconv*z as myz, % you'll get told how to adjust the prefactor
scatter/@pre marker code/.append style=/pgfplots/cube/size z=myz,%
scatter/@pre marker code/.append style=/pgfplots/cube/size x=24.3018pt,%
scatter/@pre marker code/.append style=/pgfplots/cube/size y=21.71275pt,%
scatter,only marks,
mark=my cube*,mark size=5,opacity=1,domain=0:5,domain y=0:5,samples=6,samples y=6]
f(x,y,0.2,0.4,5);
endaxis
endtikzpicture
enddocument


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 14 mins ago

























answered 1 hour ago









marmot

69.3k476148




69.3k476148











  • It would be much prettier if the sides were clearer than the upper faces.
    – AndréC
    1 hour ago










  • @AndréC What do you mean by clearer?
    – marmot
    1 hour ago






  • 1




    @marmot I think OP meant lighter shade on the top surface as shown in question.
    – nidhin
    1 hour ago






  • 1




    @AndréC Better now? The top color is set via a key, and the other color via the color map. Thanks for your great suggestion!
    – marmot
    13 mins ago






  • 1




    Ha Ha.. nice tutorial :D. @AndréC check it out.
    – Paari Vendhan
    5 mins ago
















  • It would be much prettier if the sides were clearer than the upper faces.
    – AndréC
    1 hour ago










  • @AndréC What do you mean by clearer?
    – marmot
    1 hour ago






  • 1




    @marmot I think OP meant lighter shade on the top surface as shown in question.
    – nidhin
    1 hour ago






  • 1




    @AndréC Better now? The top color is set via a key, and the other color via the color map. Thanks for your great suggestion!
    – marmot
    13 mins ago






  • 1




    Ha Ha.. nice tutorial :D. @AndréC check it out.
    – Paari Vendhan
    5 mins ago















It would be much prettier if the sides were clearer than the upper faces.
– AndréC
1 hour ago




It would be much prettier if the sides were clearer than the upper faces.
– AndréC
1 hour ago












@AndréC What do you mean by clearer?
– marmot
1 hour ago




@AndréC What do you mean by clearer?
– marmot
1 hour ago




1




1




@marmot I think OP meant lighter shade on the top surface as shown in question.
– nidhin
1 hour ago




@marmot I think OP meant lighter shade on the top surface as shown in question.
– nidhin
1 hour ago




1




1




@AndréC Better now? The top color is set via a key, and the other color via the color map. Thanks for your great suggestion!
– marmot
13 mins ago




@AndréC Better now? The top color is set via a key, and the other color via the color map. Thanks for your great suggestion!
– marmot
13 mins ago




1




1




Ha Ha.. nice tutorial :D. @AndréC check it out.
– Paari Vendhan
5 mins ago




Ha Ha.. nice tutorial :D. @AndréC check it out.
– Paari Vendhan
5 mins ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f457226%2fhow-to-plot-trinomial-distribution-in-tikz%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery