Package: anydyce
Copyright and other protections apply.
Please see the accompanyingLICENSEfile for rights and restrictions governing use of this software.
All rights not expressly waived or licensed are reserved.
If that file is missing or appears to be modified from its original, then please contact the author before viewing or using this software in any capacity.anydyce– visualization tools fordyceanydyceexposes an interactive interface todyce(the dice mechanic modeling library) inJupytersimilar toAnyDice.anydyceis licensed under theMIT License.
See the accompanyingLICENSEfile for details.
Non-experimental features should be considered stable.
See therelease notesfor a summary of version-to-version changes.
Source code isavailable on GitHub.If you find it lacking in any way, please don’t hesitate tobring it to my attention.Design philosophyanydyce(currently) targets Matplotlib (both alone and within Jupyter).
Support for additional visualization tools may be added in the future.
It is intended as a convenience layer for those who benefit from simple interfaces with reasonable defaults and limited configurability.
If you find they are too restrictive, or have any requests or ideas for improvements,let me know![^1][^1]:At some point this devolves into an exercise in chasing a diversity of very specific preferences.
If you have a very specific need, [``dyce``](https://posita.github.io/dyce/) is fairly low level and should be able to integrate directly with whatever visualization context or package you prefer.
That being said, I am always on the lookout for more intuitive or accessible visualizations and will eagerly [explore ideas with you](https://posita.github.io/anydyce/0.4/contrib/#starting-discussions-and-filing-issues).If used within Jupyter,anydyceprovidesa high-level, interactive interfacewith functionality that echos AnyDice.Comparison to AnyDiceFeatureanydyceAnyDiceShareable session URLs⚠️ Via third party[^2]✅ YesModeling language🐍PythonProprietaryComputation time limit✅ No limit❌ 5 secondsConfigurable plots(including “burst” graphs)✅ Yes❌ NoInstall and use third party libraries✅ Yes❌ NoOpen source(install, run, and modify locally)✅ Yes❌ NoAdvanced language features(memoization, nested functions, etc.)✅ Yes❌ No[^2]:Relies on external depedencies such as [Binder](https://mybinder.org/) or [JupyterLite](https://jupyterlite.readthedocs.io/en/latest/).
(See [Interactive quick start](#interactive-quick-start).)
However, edits are not persisted.
Notebooks can also be downloaded and shared as ``.ipynb`` files.Interactive quick startProbably theeasiestway to start tinkering withanydyceis withJupyterLite:Thequickstart-local.shscriptwill create a localvirtual environmentto bootstrap a local Jupyter server withanydyceinstalled and open a web browser to theintroduction notebook.Binderis another great resource that you can use to share notebooks from your Git repositories (includingGists):!!! danger "JupyterLite and Binder may not save your work!"JupyterLite attempts to make use of your browser’s local storage for saving notebook changes.
Browser environments vary, including how long local storage is persisted.
Further, Binder loses all state once its instances shut down after a period of inactivity.
Be careful to download any notebooks you wish to keep.When creating your own notebooks, including and running the following will bootstrapanydyceif it is not already installed:# Install additional requirements if necessaryimportwarningswithwarnings.catch_warnings():warnings.simplefilter("ignore")try:importanydyceexcept(ImportError,ModuleNotFoundError):requirements=["anydyce~=0.2"]try:importpiplite;awaitpiplite.install(requirements)exceptImportError:importpip;pip.main(["install"]+requirements)importanydyceInstallation and useanydyceis availableas a PyPI packageandas source.anydyce.vizprovides some rudimentary conveniences such as “burst” charts (anydyce’s take on donut charts).>>>importmatplotlib.pyplot>>>fromdyceimportH>>>fromanydyce.vizimportplot_burst>>>ax=matplotlib.pyplot.axes()>>>plot_burst(ax,2@H(6))>>>matplotlib.pyplot.show()# doctest: +SKIPSource:plot_burst_1.py--8<--"docs/assets/plot_burst_1.py"The outer ring can also be used to compare two histograms directly.
Ever been curious how your four shiny new fudge dice stack up against your trusty ol’ double six-siders?
Well wonder no more!anydyceabides.>>>df_4=4@H((-1,0,1))>>>d6_2=2@H(6)>>>ax=matplotlib.pyplot.axes()>>>plot_burst(...ax,...df_4,d6_2,...inner_cmap="turbo",...alpha=1.0,...)>>>matplotlib.pyplot.show()# doctest: +SKIPSource:plot_burst_2.py--8<--"docs/assets/plot_burst_2.py"Labels can even be overridden for interesting, at-a-glance displays.
Overrides apply counter-clockwise, starting from the 12 o’clock position.>>>defd20formatter(outcome,probability,h)->str:...vals={...-2:"crit. fail.",...-1:"fail.",...1:"succ.",...2:"crit. succ.",...}...returnvals[outcome]>>>d20=H(20)>>>ax=matplotlib.pyplot.axes()>>>plot_burst(ax,h_inner=d20,h_outer=H({...-2:d20.le(1)[1],...-1:d20.within(2,14)[0],...1:d20.within(15,19)[0],...2:d20.ge(20)[1],...}),inner_cmap="RdYlBu_r",outer_formatter=d20formatter)>>>matplotlib.pyplot.show()# doctest: +SKIPSource:plot_burst_3.py--8<--"docs/assets/plot_burst_3.py"Requirementsanydycerequires a relatively modern version of Python:CPython(3.8+)PyPy(CPython 3.8+ compatible)It has the following runtime dependencies:dycefor dice mechanic modelingipywidgetsfor interactivity in Jupytermatplotlibfor visualizinghistograms and poolsanydyce(anddyce) leveragenumeraryfor its opportunistic use ofbeartype. If you usebeartypefor type checking your code, but don’t wantanydyce,dyce, ornumeraryto use it internally, disable it withnumerary’sNUMERARY_BEARTYPEenvironment variable.See thehacking quick-startfor additional development and testing dependencies.Licenseanydyceis licensed under theMIT License.
See the includedLICENSEfile for details.
Source code isavailable on GitHub.CustomersThis could beyou! 👋Do you have a project that usesdyce?Let me know, and I’ll promote it here!And don’t forget to do your part in perpetuating gratuitous badge-ification!<!-- Markdown -->
As of version 1.1, HighRollin is
[![dyce-powered](https://raw.githubusercontent.com/posita/dyce/latest/docs/dyce-powered.svg)][dyce-powered]!
[dyce-powered]:https://posita.github.io/dyce/ "dyce-powered!"..reStructuredText - see https://docutils.sourceforge.io/docs/ref/rst/directives.html#imageAs of version 1.1, HighRollin is |dyce-powered|!..|dyce-powered|image::https://raw.githubusercontent.com/posita/dyce/latest/docs/dyce-powered.svg:align:top:target:https://posita.github.io/dyce/:alt:dyce-powered<!-- HTML -->As of version 1.1, HighRollin is<ahref="https://posita.github.io/dyce/"><imgsrc="https://raw.githubusercontent.com/posita/dyce/latest/docs/dyce-powered.svg"alt="dyce-powered"style="vertical-align: middle;"></a>!