# Plotting average result against a variable

I'm trying to figure out how to create an odd dice curve - specifically, odd when plotting between an axis of average result versus amount of dice (so xd6 gets 3.5 for x=1, 7 for x=2 and so on).

But, I can't figure out how (if?) anydice can let me control what the plot axis will be, or how to work around it anyway. Any pointers?

• Is the summary view what you want? If not, I'm not quite sure what you're asking for. Feb 11, 2022 at 20:53
• @IlmariKaronen Alas, no. I want to loop through several values of X (say, 1-10), calculate the average of a roll based on X (say, Xd6) and then plot the relationship between X and the average of the rolls. Feb 11, 2022 at 21:29
• That's exactly the "mean" curve in what Ilmari posted. Feb 12, 2022 at 2:44
• @HighDiceRoller I am evidently blind, cause I knew that. Thanks, you two! Feb 12, 2022 at 11:29
• @IlmariKaronen can you make this an answer so I can choose it? If convenient, add the instruction to hit 'graph view' for completeness' sake, and if there's a way to hide the other plots (particularly maximum) for clarity, that'll be even better! Feb 12, 2022 at 11:29

You can output each of your rolls with an appropriate title, as in:

loop N over {1..10} {
output Nd6 named "[N]d6"
}


and then switch to the summary view. Here, the uppermost chart (titled "mean") shows the average of each roll your program outputs:

If you prefer, the summary output can also be viewed in graph mode, with the black line showing the mean:

Unfortunately, there does not seem to be any way (short of writing a userscript or something like that to manipulate the AnyDice UI) to hide the "deviation", "minimum" and "maximum" outputs in summary mode and to show only the mean. This can be a problem especially in graph view mode, since for some distributions (such as those involving "exploding dice") the maximum can be significantly higher than the mean, and thus make the mean line hug the bottom of the chart when graphed.

However, one possible (though somewhat time-consuming) workaround is to switch to the "export" view mode, copy-paste the raw numeric CSV data from there to a spreadsheet (such as Excel, LibreOffice Calc or Google Sheets) and graph it there.

• An excellent and thorough response, thanks! That is exactly why I wanted to cut out maximum, and this is a fine way to do it if it comes to that! Feb 12, 2022 at 13:58

### You do not actually need anydice to do this.

Beside Ilmari Karonen's answer, you can consider the math behind this kind of dice rolling.

We know that a d6 follow a discrete uniform distribution, whose expected value $$\{\rm E}[d6]\$$ is 3.5. The expected value operator is linear, meaning that the expected value of the sum of the outcomes of two dice $$\d_1, \, d_2\$$ is the sum of the expected values of the two outcomes:

$${\rm E}[d_1 +d_2] = {\rm E}[d_1]+{\rm E}[d_2]$$

and it can be generalized to $$\X\$$ dice.

Then, you can directly compute the expected value of Xd6, which reads as $${\rm E}[Xd6] = X\cdot{\rm E}[d6] = X\cdot3.5$$

Hence, you can plot the dependence of the expected value on the number of d6 rolled, by considering the function

$$y = 3.5x$$

in the Cartesian Plane. Down below you can find an example written in Python.

import numpy as np
import matplotlib.pyplot as plt

average = np.zeros(10)
for x in np.arange(1,11,1):
average[x-1] = x*3.5

plt.plot(np.arange(1,11,1),average,'o--')
plt.xlabel("Number of Dice")
plt.ylabel("Expected value")


You can generalize this approach: for example you can plot the variance or the standard deviation of Xd6, or the expected value of Xd12 or other kind of dice.