### Install Development Environment Source: https://github.com/posita/anydyce/blob/main/helpers/release-checklist.md This command installs the project in editable mode with development dependencies and sets up pre-commit hooks. It assumes you are in the repository root. ```bash pip install --editable '.[dev]' && python -m pre_commit install ``` -------------------------------- ### Clone and Set Up Development Environment (Shell) Source: https://github.com/posita/anydyce/blob/main/docs/contrib.md This snippet demonstrates cloning the anydyce repository with submodules, creating and activating a Python virtual environment, installing development dependencies, and setting up pre-commit hooks. ```sh % git clone --recurse-submodules https://github.com/posita/anydyce.git % cd anydyce % /path/to/python -m venv .venv % . .venv/bin/activate % pip install --upgrade --editable '.[dev]' % python -m pre_commit install ``` -------------------------------- ### Bootstrap AnyDyce in Python Source: https://github.com/posita/anydyce/blob/main/README.md This Python code snippet installs and imports the AnyDyce library. It handles potential ImportError or ModuleNotFoundError by attempting to install the library using 'piplite' (for environments like JupyterLite) or 'pip' (for standard Python environments). It's designed to be run within notebooks or similar environments. ```python # Install additional requirements if necessary import warnings with warnings.catch_warnings(): warnings.simplefilter("ignore") try: import anydyce except (ImportError, ModuleNotFoundError): requirements = ["anydyce~=0.2"] try: import piplite ; await piplite.install(requirements) except ImportError: import pip ; pip.main(["install"] + requirements) import anydyce ``` -------------------------------- ### Run Asset Sanity Check with Tox Source: https://github.com/posita/anydyce/blob/main/helpers/release-checklist.md This command executes the 'assets' tox environment to perform a sanity check on project assets. Ensure tox is installed and configured. ```bash tox -e assets ``` -------------------------------- ### Install and Import AnyDyce for Jupyter Source: https://github.com/posita/anydyce/blob/main/docs/notebooks/anydyce_intro.ipynb This code block handles the installation of necessary Python packages like ipywidgets, matplotlib, and anydyce, especially within Jupyterlite environments. It ensures that the anydyce library is available for use in subsequent visualizations. It includes error handling for import failures and specific workarounds for Jupyterlite issues. ```python # Install additional requirements if necessary import warnings with warnings.catch_warnings(): warnings.simplefilter("ignore") try: import anydyce except (ImportError, ModuleNotFoundError): requirements = ["ipywidgets==8.1.3", "matplotlib==3.5.2", "anydyce==0.4.6"] try: import piplite ; await piplite.install(requirements, keep_going=True) # Work around import matplotlib.pyplot ; matplotlib.pyplot.clf() except ImportError: import pip ; pip.main(["install"] + requirements) import anydyce ``` -------------------------------- ### Python: Remove numerary types and Link Example Notebook Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This version removes the use of specific `numerary.types` and adds a link to an external Gist repository for an example notebook. It also includes a comparison table in the `README.md`. ```python Removes use of #!python numerary.types....SCU types. Links to an external (Gist) repository for example notebook. Adds comparison table to AnyDice to README.md. ``` -------------------------------- ### Serve and Check Documentation with MkDocs Source: https://github.com/posita/anydyce/blob/main/helpers/release-checklist.md No description ```bash tox -e check && "$( git rev-parse --show-toplevel )/.tox/check/bin/mkdocs" serve ``` -------------------------------- ### Run Tests with Tox and Pytest (Shell) Source: https://github.com/posita/anydyce/blob/main/docs/contrib.md This snippet shows how to navigate to the anydyce project directory, activate the virtual environment, and execute tests using Tox, with optional arguments for both Tox and Pytest. ```sh % cd …/path/to/anydyce % . .venv/bin/activate % tox [TOX_ARGS... [-- PYTEST_ARGS...]] ``` -------------------------------- ### Python: Update dyce and Migrate to versioningit Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This update completes the transition to `dyce~=0.6` and changes the version management system from `setuptools_scm` to `versioningit`. The latter offers more flexibility in version number formatting and enables CI-based PyPI deployments. ```python Completes update to #!python dyce~=0.6. Migrates from #!python setuptools_scm to #!python versioningit for more flexible version number formatting. Allows deployments to PyPI from CI based on tags. ``` -------------------------------- ### HPlotterChooser Documentation Source: https://github.com/posita/anydyce/blob/main/docs/anydyce.md Documentation for the HPlotterChooser class, which likely handles the selection of plotting tools. ```APIDOC ## anydyce.viz.HPlotterChooser ### Description Documentation for the HPlotterChooser class. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Propagate Version Information using Shell Script Source: https://github.com/posita/anydyce/blob/main/helpers/release-checklist.md This command executes a shell script to propagate the next version number across the project. It uses 'versioningit' to determine the next version. ```bash "$( git rev-parse --show-toplevel )/helpers/propagate-version.sh" "$( python -m versioningit --next-version . )" ``` -------------------------------- ### jupyter_visualize Documentation Source: https://github.com/posita/anydyce/blob/main/docs/anydyce.md Documentation for the jupyter_visualize function, used for visualizing data within Jupyter environments. ```APIDOC ## anydyce.viz.jupyter_visualize ### Description Documentation for the jupyter_visualize function, used for visualizing data within Jupyter environments. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Anydyce Viz Package Components Source: https://github.com/posita/anydyce/blob/main/docs/anydyce.viz.md This section lists the primary components and functions available in the anydyce.viz package, designed for use with Matplotlib. ```APIDOC ## Package: anydyce.viz ### Description This package provides experimental utilities for integration with Matplotlib. ### Components and Functions: - **HLikeT**: Type hint for horizontal-like data. - **ImageType**: Type for image data. - **TraditionalPlotType**: Type for traditional plot data. - **HPlotter**: Base class for horizontal plotters. - **BarHPlotter**: Plotter for bar charts (horizontal). - **BurstHPlotter**: Plotter for burst data (horizontal). - **HorizontalBarHPlotter**: Specific plotter for horizontal bar charts. - **LineHPlotter**: Plotter for line charts (horizontal). - **ScatterHPlotter**: Plotter for scatter plots (horizontal). - **PlotWidgets**: Collection of plotting widgets. - **cumulative_probability_formatter**: Formatter for cumulative probabilities. - **outcome_name_formatter**: Formatter for outcome names. - **outcome_name_probability_formatter**: Formatter for outcome names and probabilities. - **limit_for_display**: Utility to determine display limits. - **probability_formatter**: Formatter for probabilities. - **values_xy_for_graph_type**: Function to get X, Y values for graph types. - **plot_bar**: Function to create a bar plot. - **plot_line**: Function to create a line plot. - **plot_scatter**: Function to create a scatter plot. - **plot_burst**: Function to plot burst data. - **plot_burst_subplot**: Function to plot burst data in a subplot. ``` -------------------------------- ### Tag Release with Signed Tag Source: https://github.com/posita/anydyce/blob/main/helpers/release-checklist.md This command creates a signed Git tag for the release. The tag message is populated with the commit history, and the tag name is based on the next version number. ```bash git tag [--force] --message "$( git rev-list --format=%B --max-count=1 HEAD )" --sign "v$( python -m versioningit --next-version . )" ``` -------------------------------- ### Force Push 'latest' Tag Source: https://github.com/posita/anydyce/blob/main/helpers/release-checklist.md This command forces the push of the 'latest' tag to the 'origin' remote. This is typically used to update a 'latest' pointer. ```bash git tag --force latest && git push origin --force latest ``` -------------------------------- ### Adding Contributor Information to LICENSE file Source: https://github.com/posita/anydyce/blob/main/docs/contrib.md Instructions on how to add personal information to the LICENSE file, following a specific markdown format. This includes name, email, and GitHub username. ```markdown ... * [Matt Bogosian](mailto:matt@bogosian.net?Subject=anydyce); GitHub – [**@posita**](https://github.com/posita) ... ``` -------------------------------- ### Commit Updated Files and Create Commit Message Source: https://github.com/posita/anydyce/blob/main/helpers/release-checklist.md This command stages all updated files and creates a new commit with an edited message. The commit message is pre-populated with a placeholder for release notes and the next version number. ```bash git add --update && git commit --edit --message "$( printf 'Release v%s\n\n' "$( python -m versioningit --next-version . )" )" ``` -------------------------------- ### Visualize with HPlotterChooser in AnyDyce Source: https://github.com/posita/anydyce/blob/main/docs/anydyce.md The HPlotterChooser class in anydyce.viz is used for selecting and visualizing data. It allows for different plotting options to be chosen based on the data structure. No specific dependencies are mentioned, and it is intended for use within the AnyDyce framework. ```python from anydyce.viz import HPlotterChooser # Example usage (conceptual): # plotter_chooser = HPlotterChooser(data) # plotter_chooser.plot() ``` -------------------------------- ### Jupyter Visualization in AnyDyce Source: https://github.com/posita/anydyce/blob/main/docs/anydyce.md The jupyter_visualize function from anydyce.viz is designed for rendering visualizations within a Jupyter Notebook environment. It likely handles the necessary formatting and output for interactive plotting. Specific input and output details are not provided, but it integrates with Jupyter's display system. ```python from anydyce.viz import jupyter_visualize # Example usage (conceptual): # jupyter_visualize(data, **options) ``` -------------------------------- ### Push Current Branch to Origin Source: https://github.com/posita/anydyce/blob/main/helpers/release-checklist.md This command pushes the current branch to the 'origin' remote. It can optionally use '--force' to overwrite remote history. ```bash git push origin [--force] "$( git describe --abbrev=0 )" ``` -------------------------------- ### Python: Add Transparency and PNG/SVG Output Options Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This update adds support for transparency in visualizations, along with options to output and download plots in PNG and SVG formats. It also resolves display inconsistencies between Jupyter Lab and Jupyter Lite. ```python Adds transparency as well as PNG and SVG output and download selections. Fixes display inconsistencies between Jupyter Lab and Jupyter Lite. ``` -------------------------------- ### Create Burst, Bar, and Line Charts with AnyDyce Source: https://github.com/posita/anydyce/blob/main/docs/notebooks/anydyce_intro.ipynb This Python code demonstrates the use of anydyce's lower-level visualization functions (plot_bar, plot_burst, plot_line) for creating detailed charts. It compares the distributions of '2d10' and 'd8+d12' using a burst chart, a bar chart, and a line chart, allowing for in-depth analysis and visual comparison of different dice mechanics. It also customizes colors and styles using matplotlib. ```python from anydyce.viz import plot_bar, plot_burst, plot_line from dyce import H import matplotlib.pyplot import matplotlib.style matplotlib.style.use("bmh") matplotlib.pyplot.rcParams["figure.figsize"] = (10, 10) d10_2 = 2@H(10) d10_2_label = "2d10" d8d12 = H(8) + H(12) d8d12_label = "d8+d12" # Burst chart ax = matplotlib.pyplot.subplot2grid((2, 2), (0, 0), colspan=2) plot_burst( ax, h_inner=d10_2, h_outer=d8d12, inner_cmap="Purples_r", outer_cmap="Greens_r", alpha=0.8, title=f"Outer: {d8d12_label}\nInner: {d10_2_label}", ) # Bar chart ax = matplotlib.pyplot.subplot2grid((2, 2), (1, 0)) plot_bar(ax, [ (d10_2_label, d10_2), (d8d12_label, d8d12), ], alpha=0.8) # Re-color the bars so_far = 0 for count, color in zip( (len(h) for h in (d10_2, d8d12)), ("tab:purple", "tab:green"), ): for i in range(count): ax.patches[i + so_far].set_color(color) so_far += count ax.legend() # Line chart ax = matplotlib.pyplot.subplot2grid((2, 2), (1, 1)) plot_line(ax, [ (d10_2_label, d10_2), (d8d12_label, d8d12), ], markers="<>", alpha=0.8) # Re-color the lines ax.lines[0].set_color("tab:purple") ax.lines[1].set_color("tab:green") ax.legend() matplotlib.pyplot.tight_layout()matplotlib.pyplot.show() ``` -------------------------------- ### Python: Refactor jupyter_visualize with HPlotterChooser Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This version introduces the `HPlotterChooser` implementation and significantly refactors the `jupyter_visualize` function to utilize it. This aims to improve the visualization capabilities and structure. ```python Adds #!python HPlotterChooser implementation and substantially refactors #!python jupyter_visualize in support thereof. ``` -------------------------------- ### Python: Add Required Dependencies ipywidgets and matplotlib Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This version mandates `ipywidgets` and `matplotlib` as required dependencies for the project. It also includes minor corrections to the specified Python version requirements. ```python ipywidgets and matplotlib are now required dependencies. Minor corrections to required Python version. ``` -------------------------------- ### Create Basic Burst Chart with anydyce in Python Source: https://github.com/posita/anydyce/blob/main/README.md This code creates a basic burst chart using the anydyce library to visualize the probability distribution of rolling two six-sided dice. It requires the matplotlib library for plotting and the anydyce library for dice probability calculations. The chart is then displayed using matplotlib. ```python >>> import matplotlib.pyplot >>> from dyce import H >>> from anydyce.viz import plot_burst >>> ax = matplotlib.pyplot.axes() >>> plot_burst(ax, 2@H(6)) >>> matplotlib.pyplot.show() # doctest: +SKIP ``` -------------------------------- ### Embed 'dyce-powered' Badge in HTML Source: https://github.com/posita/anydyce/blob/main/README.md This snippet illustrates embedding the 'dyce-powered' badge within an HTML structure. It uses an anchor tag (``) linking to the dyce project and an image tag (``) to display the badge, with inline styling for vertical alignment. This is useful for web pages or any HTML-based documentation. ```html As of version 1.1, HighRollin is dyce-powered! ``` -------------------------------- ### Python: Migrates to ipywidgets~=8.0 Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This release updates the project's dependency on `ipywidgets` to version 8.0. This migration is a significant change that may introduce new features or require adjustments in how `ipywidgets` are used. ```python Migrates to #!python ipywidgets~=8.0 ``` -------------------------------- ### Clean Untracked Files with Git Source: https://github.com/posita/anydyce/blob/main/helpers/release-checklist.md This command removes untracked files from the Git repository. The '-n' flag can be used for a dry run to see what would be removed without actually deleting anything. ```bash git clean -Xdf [-n] [...] ``` -------------------------------- ### Python: Add burst_columns Widget and Histogram Specs Source: https://github.com/posita/anydyce/blob/main/docs/notes.md Introduces a new widget for 'burst_columns' and allows 'None' as a valid value for 'histogram_specs' in HPlotterChooser and jupyter_visualize. This enhances flexibility in visualization settings. ```python Add #!python SettingsDict["burst_columns"] and related widget. Added #!python None as an acceptable item value for #!python histogram_specs parameter ``` -------------------------------- ### Python: Add limit_for_display and Update jupyter_visualize Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This update introduces the `limit_for_display` function and updates the `jupyter_visualize` function. These changes likely enhance data handling and visualization capabilities within the Jupyter environment. ```python Adds #!python limit_for_display and updates #!python jupyter_visualize. ``` -------------------------------- ### Embed 'dyce-powered' Badge in Markdown Source: https://github.com/posita/anydyce/blob/main/README.md This snippet demonstrates how to embed the 'dyce-powered' badge in Markdown. It includes the image link and a tooltip for hover effects. This is a common way to visually indicate a project's powered-by status. ```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!" ``` -------------------------------- ### Python: Restore Rich Display Hook Methods in anydyce.viz.Image Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This fix restores the rich display hook methods for `anydyce.viz.Image` that were accidentally removed in a previous version (v0.4.2). This resolves issues with displaying interactive plots. ```python Restore rich display hook methods accidentally removed from #!python anydyce.viz.Image ``` -------------------------------- ### Python: Update ipywidgets Dependency (>=7.5,<9) Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This update relaxes the ipywidgets dependency to a broader range, aiming to improve compatibility with JupyterLite. Previously, a stricter version caused crashes. ```python relax ipywidgets dependency to >=7.5,<9 ``` -------------------------------- ### Python: Add values_xy_for_graph_type and New Graph Types Source: https://github.com/posita/anydyce/blob/main/docs/notes.md Introduces the experimental `values_xy_for_graph_type` function and exposes new 'at least' and 'at most' graph types through the `jupyter_visualize` interface. This prepares for upcoming breaking changes in `dyce~=0.6`. ```python Prepares for breaking changes in future release of #!python dyce~=0.6. Adds experimental #!python values_xy_for_graph_type function and exposes new “at least” and “at most” graph types via #!python jupyter_visualize interface. ``` -------------------------------- ### Visualize Powered by the Apocalypse (PbtA) Mechanics Source: https://github.com/posita/anydyce/blob/main/docs/notebooks/anydyce_intro.ipynb This Python code uses anydyce to visualize the probability distributions for the Powered by the Apocalypse (PbtA) core mechanic. It defines a function to categorize dice roll results (fail, cost, success) and then generates visualizations for different modifier values applied to 2d6 rolls. This helps in understanding the impact of modifiers on PbtA game outcomes. ```python from anydyce import jupyter_visualize from dyce import H from dyce.evaluation import HResult, foreach from enum import IntEnum, auto class PBTA(IntEnum): FAIL = 0 COST = auto() SUCC = auto() def pbta(result: HResult): if result.outcome <= 6: return PBTA.FAIL elif result.outcome >= 10: return PBTA.SUCC else: return PBTA.COST jupyter_visualize( ( (f"PBTA {mod:+}", foreach(pbta, result=(2@H(6)) + mod), ((2@H(6)) + mod)) for mod in range(-1, 4) ), initial_burst_cmap_link=False, initial_burst_cmap_outer="Greys", ) ``` -------------------------------- ### Compare Dice Histograms with anydyce plot_burst in Python Source: https://github.com/posita/anydyce/blob/main/README.md This code compares two dice histograms (4 fudge dice vs. 2 six-sided dice) using a burst chart in anydyce. It relies on matplotlib for plotting and anydyce for histogram generation and plotting. The resulting chart visualizes the probability distributions of the two dice sets for comparison. ```python >>> 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: +SKIP ``` -------------------------------- ### Python: Fix Image Display in JupyterLite Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This release addresses a critical bug where rich display hook methods were removed from `anydyce.viz.Image`, breaking interactive plot display. This version restores those methods. ```python This release inadvertently removed rich display hook methods from #!python anydyce.viz.Image. That broke the ability to display interactive plots. ``` -------------------------------- ### Embed 'dyce-powered' Badge in reStructuredText Source: https://github.com/posita/anydyce/blob/main/README.md This snippet shows how to embed the 'dyce-powered' badge using reStructuredText syntax. It utilizes the 'image' directive to include the badge with specified alignment, target URL, and alt text. This is suitable for documentation generated with tools like Sphinx. ```rst .. reStructuredText - see https://docutils.sourceforge.io/docs/ref/rst/directives.html#image As 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 ``` -------------------------------- ### Python: Disable Data Limiting by Default in jupyter_visualize Source: https://github.com/posita/anydyce/blob/main/docs/notes.md This change modifies the default behavior of `jupyter_visualize` by turning off data limiting. This adjustment aims to provide a different default user experience for data visualization. ```python Turns data limiting off by default in #!python jupyter_visualize. ``` -------------------------------- ### Visualize Dice Rolls with AnyDyce in Jupyter Source: https://github.com/posita/anydyce/blob/main/docs/notebooks/anydyce_intro.ipynb This Python code snippet demonstrates how to use anydyce's jupyter_visualize function to create an interactive visualization of dice roll outcomes. It calculates the highest, middle, and lowest values of rolling 3d6 and displays them as a line plot. This is useful for understanding probability distributions of dice mechanics. ```python from anydyce import jupyter_visualize from dyce import P p_3d6 = 3@P(6) jupyter_visualize( ( p_3d6.h(-1), # highest p_3d6.h(1), # middle p_3d6.h(0), # lowest ), initial_markers="o", selected_name="Line Plot", ) ``` -------------------------------- ### Customize Labels on Burst Chart with anydyce in Python Source: https://github.com/posita/anydyce/blob/main/README.md This code demonstrates how to customize labels on a burst chart in anydyce to represent critical success/failure ranges on a d20 roll. It depends on matplotlib for plotting and anydyce for dice histogram generation. The `d20formatter` function maps outcome values to custom labels, enhancing chart interpretability. ```python >>> def d20formatter(outcome, probability, h) -> str: ... vals = { ... -2: "crit. fail.", ... -1: "fail.", ... 1: "succ.", ... 2: "crit. succ.", ... } ... return vals[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: +SKIP ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.