{"id":13493949,"url":"https://github.com/gyli/PyWaffle","last_synced_at":"2025-03-28T13:31:29.144Z","repository":{"id":35134662,"uuid":"110738701","full_name":"gyli/PyWaffle","owner":"gyli","description":"🧇 Make Waffle Charts in Python.","archived":false,"fork":false,"pushed_at":"2024-06-16T04:23:17.000Z","size":3413,"stargazers_count":591,"open_issues_count":6,"forks_count":106,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-02-04T00:47:19.488Z","etag":null,"topics":["charts","data-visualization","matplotlib","python","visualization","waffle","waffle-charts"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gyli.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-14T20:03:47.000Z","updated_at":"2025-01-12T16:30:47.000Z","dependencies_parsed_at":"2024-06-18T15:40:02.363Z","dependency_job_id":"fd5e4690-73f0-41e2-a905-4220b2c09472","html_url":"https://github.com/gyli/PyWaffle","commit_stats":{"total_commits":293,"total_committers":7,"mean_commits":"41.857142857142854","dds":0.04778156996587035,"last_synced_commit":"be164414810841a696f02eb58d0e25b39b1d4c4e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyli%2FPyWaffle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyli%2FPyWaffle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyli%2FPyWaffle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gyli%2FPyWaffle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gyli","download_url":"https://codeload.github.com/gyli/PyWaffle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246037345,"owners_count":20713399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["charts","data-visualization","matplotlib","python","visualization","waffle","waffle-charts"],"created_at":"2024-07-31T19:01:20.233Z","updated_at":"2025-03-28T13:31:28.604Z","avatar_url":"https://github.com/gyli.png","language":"Python","funding_links":[],"categories":["Python","其他_机器学习与深度学习","数据可视化"],"sub_categories":[],"readme":"# PyWaffle\n\n[![PyPI version](https://badge.fury.io/py/pywaffle.svg)](https://pypi.org/project/pywaffle/)\n[![ReadTheDocs](https://readthedocs.org/projects/pywaffle/badge/?version=latest\u0026style=flat)](http://pywaffle.readthedocs.io/)\n[![Binder](https://img.shields.io/badge/run-Online%20Demo-blue)](https://mybinder.org/v2/gh/gyli/PyWaffle/master?filepath=demo.ipynb)\n\nPyWaffle is an open source, MIT-licensed Python package for plotting waffle charts.\n\nIt provides a [Figure constructor class](https://matplotlib.org/gallery/subplots_axes_and_figures/custom_figure_class.html) `Waffle`, which could be passed to [matplotlib.pyplot.figure](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.figure.html) and generates a matplotlib Figure object.\n\nPyPI Page: [https://pypi.org/project/pywaffle/](https://pypi.org/project/pywaffle/)\n\nDocumentation: [http://pywaffle.readthedocs.io/](http://pywaffle.readthedocs.io/)\n\n## Installation\n\n```python\npip install pywaffle\n```\n\n## Requirements\n\n* Python 3.5+\n* Matplotlib\n\n## Examples\n\n### 1. Value Scaling\n\n```python\nimport matplotlib.pyplot as plt\nfrom pywaffle import Waffle\n```\n\n```python\nfig = plt.figure(\n    FigureClass=Waffle, \n    rows=5, \n    columns=10, \n    values=[48, 46, 6],\n    figsize=(5, 3)\n)\nplt.show()\n```\n\n![basic](examples/readme/basic.svg)\n\nThe values are automatically scaled to 24, 23 and 3 to fit 5 * 10 chart size.\n\n`FigureClass` and `figsize` are parameters of `matplotlib.pyplot.figure`, you may find the full parameter list on [matplotlib.pyplot.figure](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.figure.html) function reference.  \n\nOther parameters, including `rows`, `columns`, and `values` in this example, are from `Waffle`, and see PyWaffle's [API Reference](https://pywaffle.readthedocs.io/en/latest/class.html) for details.\n\n### 2. Values in dict \u0026 Auto-sizing\n\n```python\ndata = {'Cat1': 10, 'Cat2': 7, 'Cat3': 9}\nfig = plt.figure(\n    FigureClass=Waffle,\n    rows=5,\n    values=data,\n    legend={'loc': 'upper left', 'bbox_to_anchor': (1.05, 1)},\n)\nplt.show()\n```\n\n![Use values in dictionary; use absolute value as block number, without defining columns](examples/readme/absolute_block_numbers.svg)\n\nIn this example, only `rows` is specified and `columns` is empty, absolute values in `values` are used as block numbers. Similarly, `rows` could also be optional if `columns` is specified.\n\nIf `values` is a dict, the keys will be used as labels in the legend.\n\n### 3. More style settings including Legend, Title, Colors, Direction, Arranging Style, etc.\n\n```python\ndata = {'Car': 58, 'Pickup': 21, 'Truck': 11, 'Motorcycle': 7}\nfig = plt.figure(\n    FigureClass=Waffle,\n    rows=5,\n    values=data,\n    colors=[\"#C1D82F\", \"#00A4E4\", \"#FBB034\", '#6A737B'],\n    title={'label': 'Vehicle Sales by Vehicle Type', 'loc': 'left'},\n    labels=[f\"{k} ({v}%)\" for k, v in data.items()],\n    legend={'loc': 'lower left', 'bbox_to_anchor': (0, -0.4), 'ncol': len(data), 'framealpha': 0},\n    starting_location='NW',\n    vertical=True,\n    block_arranging_style='snake'\n)\nfig.set_facecolor('#EEEEEE')\nplt.show()\n```\n\n![Add title, legend and background color; customize the block color](examples/readme/title_and_legend.svg)\n\nParameter `colors` allows you to change the block color, and it accepts a list of colors that matplotlib can recognize, including hex, RGB in tuple, single character notation, etc. See Matplotlib [Colors](https://matplotlib.org/stable/tutorials/colors/colors.html#specifying-colors) for details. \n\nParameter `title` and `legend` accept the same parameters as in Matplotlib, [matplotlib.pyplot.title](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.title.html) and [matplotlib.pyplot.legend](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html).\n\nParameter `starting_location`, `vertical`, and `block_arranging_style` controls [Where to Start First Block](https://pywaffle.readthedocs.io/en/latest/examples/block_shape_spacing_location_direction_and_style.html#where-to-start-first-block), [Plotting Direction](https://pywaffle.readthedocs.io/en/latest/examples/block_shape_spacing_location_direction_and_style.html#plotting-direction), and [Where to Start Each Category](https://pywaffle.readthedocs.io/en/latest/examples/block_shape_spacing_location_direction_and_style.html#where-to-start-each-category). \n\nYou may find more details under [Examples](https://pywaffle.readthedocs.io/en/latest/examples.html) section in PyWaffle Documentation. \n\n### 4. Plot with Icons - Pictogram Chart\n\n```python\ndata = {'Car': 58, 'Pickup': 21, 'Truck': 11, 'Motorcycle': 7}\nfig = plt.figure(\n    FigureClass=Waffle,\n    rows=5,\n    values=data,\n    colors=[\"#c1d82f\", \"#00a4e4\", \"#fbb034\", '#6a737b'],\n    legend={'loc': 'upper left', 'bbox_to_anchor': (1, 1)},\n    icons=['car-side', 'truck-pickup', 'truck', 'motorcycle'],\n    font_size=12,\n    icon_legend=True\n)\nplt.show()\n```\n    \n![Use Font Awesome icons](examples/readme/fontawesome.svg)\n\nPyWaffle supports [Font Awesome](https://fontawesome.com/) icons in the chart. See [Plot with Characters or Icons](https://pywaffle.readthedocs.io/en/latest/examples/plot_with_characters_or_icons.html) for details.\n\n### 5. Plotting on Existed Figure and Axis\n\n```python\nfig = plt.figure()\nax = fig.add_subplot(111)\n\n# Modify existed axis\nax.set_title(\"Axis Title\")\nax.set_aspect(aspect=\"equal\")\n\nWaffle.make_waffle(\n    ax=ax,  # pass axis to make_waffle\n    rows=5, \n    columns=10, \n    values=[30, 16, 4], \n    title={\"label\": \"Waffle Title\", \"loc\": \"left\"}\n)\n```\n\n![Plotting on Existed Figure and Axis](examples/readme/existed_axis.svg)\n\n### 6. Multiple Plots in One Chart\n\n```python\nimport pandas as pd\ndata = pd.DataFrame(\n    {\n        'labels': ['Car', 'Truck', 'Motorcycle'],\n        'Factory A': [32384, 13354, 5245],\n        'Factory B': [22147, 6678, 2156],\n        'Factory C': [8932, 3879, 896],\n    },\n).set_index('labels')\n\n# A glance of the data:\n#             Factory A  Factory B  Factory C\n# labels\n# Car             27384      22147       8932\n# Truck            7354       6678       3879\n# Motorcycle       3245       2156       1196\n\nfig = plt.figure(\n    FigureClass=Waffle,\n    plots={\n        311: {\n            'values': data['Factory A'] / 1000,  # Convert actual number to a reasonable block number\n            'labels': [f\"{k} ({v})\" for k, v in data['Factory A'].items()],\n            'legend': {'loc': 'upper left', 'bbox_to_anchor': (1.05, 1), 'fontsize': 8},\n            'title': {'label': 'Vehicle Production of Factory A', 'loc': 'left', 'fontsize': 12}\n        },\n        312: {\n            'values': data['Factory B'] / 1000,\n            'labels': [f\"{k} ({v})\" for k, v in data['Factory B'].items()],\n            'legend': {'loc': 'upper left', 'bbox_to_anchor': (1.2, 1), 'fontsize': 8},\n            'title': {'label': 'Vehicle Production of Factory B', 'loc': 'left', 'fontsize': 12}\n        },\n        313: {\n            'values': data['Factory C'] / 1000,\n            'labels': [f\"{k} ({v})\" for k, v in data['Factory C'].items()],\n            'legend': {'loc': 'upper left', 'bbox_to_anchor': (1.3, 1), 'fontsize': 8},\n            'title': {'label': 'Vehicle Production of Factory C', 'loc': 'left', 'fontsize': 12}\n        },\n    },\n    rows=5,  # Outside parameter applied to all subplots, same as below\n    cmap_name=\"Accent\",  # Change color with cmap\n    rounding_rule='ceil',  # Change rounding rule, so value less than 1000 will still have at least 1 block\n    figsize=(6, 5)\n)\n\nfig.suptitle('Vehicle Production by Vehicle Type', fontsize=14, fontweight='bold')\nfig.supxlabel('1 block = 1000 vehicles', fontsize=8, x=0.14)\nfig.set_facecolor('#EEEDE7')\n\nplt.show()\n```\n    \n![Multiple plots](examples/readme/multiple_plots.svg)\n\n## Demo\n\nWanna try it yourself? There is [Online Demo](https://mybinder.org/v2/gh/gyli/PyWaffle/master?filepath=demo.ipynb)!\n\n## What's New\n\nSee [CHANGELOG](CHANGELOG.md)\n\n## License\n\n* PyWaffle is under MIT license, see `LICENSE` file for the details.\n* The Font Awesome font is licensed under the SIL OFL 1.1: http://scripts.sil.org/OFL\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyli%2FPyWaffle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgyli%2FPyWaffle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyli%2FPyWaffle/lists"}