Pygal is an open-source Python library for creating dynamic and interactive SVG (Scalar Vector Graphics) charts. It is known for its ease of use, allowing developers to generate high-quality, scalable visualizations with minimal code. Pygal is currently at version 3.1.0 and maintains an active development and release cadence, with recent updates focusing on fixes and minor enhancements.
pip install pygalVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a simple bar chart with two data series and render it to an SVG file. It also shows the (commented out) option to render directly in a web browser, which requires the `lxml` optional dependency.
Embed the SVG using `<embed type="image/svg+xml" src="your_chart.svg">` or render the chart directly into a Flask/Django response, which typically handles embedding correctly. Alternatively, manually add the font stylesheet to your main HTML file.
Use `chart.render_data_uri()` to get a base64 encoded URI, which can then be displayed in Jupyter using `IPython.display.HTML`. For file output, use `render_to_file()` and open the `.svg` file in a web browser. For interactive display, `render_in_browser()` (requires `lxml`) can be used, but this will open a new browser tab.
Ensure you are using Python 3.8 or newer. Update your development environment to use recent versions of `pytest` if you are running tests against Pygal's internals. Migrate any custom code that might have indirectly relied on these deprecated Python features or library internals.
Install `cairosvg` separately (`pip install cairosvg`) or install Pygal with the `[all]` extra: `pip install "pygal[all]"`.
Ensure pygal is installed for the correct Python environment using `pip install pygal`. If using an IDE, verify that the project interpreter is set to the environment where pygal is installed.
Rename your Python script file to something other than `pygal.py` (e.g., `my_chart.py`) to avoid shadowing the pygal library.
Filter out or replace `None` values in your data with appropriate empty strings or default numeric values before passing them to pygal chart methods like `add()` or when setting labels.