{"id":17541763,"url":"https://github.com/anoopkcn/plotreset","last_synced_at":"2026-02-21T10:02:23.103Z","repository":{"id":129878472,"uuid":"479201324","full_name":"anoopkcn/plotreset","owner":"anoopkcn","description":"reset, customize, save, load matplotlib plot styles","archived":false,"fork":false,"pushed_at":"2025-01-11T18:06:56.000Z","size":161,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-29T14:49:23.763Z","etag":null,"topics":["academic","context-plots","graph","matplotlib","multi-plots","plot","plt"],"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/anoopkcn.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null}},"created_at":"2022-04-08T01:18:57.000Z","updated_at":"2025-11-05T20:49:25.000Z","dependencies_parsed_at":"2025-04-23T23:14:22.705Z","dependency_job_id":"e79457f4-4e4a-4f01-93ab-86518651e245","html_url":"https://github.com/anoopkcn/plotreset","commit_stats":null,"previous_names":["anoopkcn/plotreset"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/anoopkcn/plotreset","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anoopkcn%2Fplotreset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anoopkcn%2Fplotreset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anoopkcn%2Fplotreset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anoopkcn%2Fplotreset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anoopkcn","download_url":"https://codeload.github.com/anoopkcn/plotreset/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anoopkcn%2Fplotreset/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29679049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T09:33:50.764Z","status":"ssl_error","status_checked_at":"2026-02-21T09:33:19.949Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["academic","context-plots","graph","matplotlib","multi-plots","plot","plt"],"created_at":"2024-10-20T23:08:09.021Z","updated_at":"2026-02-21T10:02:23.086Z","avatar_url":"https://github.com/anoopkcn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# plotreset\nPlotReset is a Python package that provides a simple way to reset and customize `matplotlib` plot styles. Comes with a sensible set of defaults for academic use. You can also extend the styles by adding more templates. Save and load templates in a JSON format to reuse.\n\n## Installation\n```bash\npip install plotreset\n```\n## Usage\n```python\nfrom plotreset import Styles\nstyle=Styles('reset')\n```\nThen create a style object. Note that when you create the object with a specific style template name(`reset`, `academic` etc,.) it sets the style for you plots. All the plots you make after this will have the style applied.\n\n```python\nstyle=Styles('academic')\n```\nWhere `academic` is a `plotreset` style(you can write your own or modify `academic` defaults) where latex font and settings are preloaded.\n\n**To revert back to `matplotlib` default template simply create the object without any arguments**\n```python\nstyle=Styles()\n```\n### Example:\n\n## Example.1 using the `reset` style template:\n\n```python\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom plotreset import Styles\n\nstyle = Styles(\"reset\")\n\nplt.figure()\nx = np.linspace(-5, 5, 200)\ny = 1 / (np.sqrt(2 * np.pi)) * np.exp(-(x**2) / 2)\ny2 = 1 / (np.sqrt(2 * np.pi * 2)) * np.exp(-(x**2) / (2 * 0.5))\ny3 = 1 / (np.sqrt(2 * np.pi * 2)) * np.exp(-(x**2) / (2 * 1.5))\nplt.plot(x, y, label=\"Gaussian Distribution\")\nplt.plot(x, y2, label=\"Gaussian Distribution\")\nplt.plot(x, y3, label=\"Gaussian Distribution\")\nplt.savefig(\"examples/simple.svg\")\nplt.show()\n```\n\u003cimg src=\"https://raw.githubusercontent.com/anoopkcn/plotreset/refs/heads/main/examples/simple.svg\" alt=\"simple\" role=\"img\"\u003e\n\nYou can update the style settings:\n```python\nstyle.font.size = 18\nstyle.font.family = \"serif\"\nstyle.axes.grid = True\nstyle.grid.alpha: 0.7\n\nplt.plot(x, y, label=\"Gaussian Distribution\")\n```\n\n### Example.2 using the `academic` style template and cycles:\n\n`plotreset` also comes with a predefined set of defaults that can be used for example:\n\nto cycle through colors, linestyles, markers, etc.\n\n```python\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom cycler import cycler\n\nfrom plotreset import Styles, defaults\n\nstyle = Styles(\"reset\")\nc1 = cycler(color=defaults.COLORS[:4])\nc2 = cycler(linestyle=defaults.LINE_STYLES[:4])\nc3 = cycler(marker=defaults.MARKERS[:4])\n\n\nx = np.linspace(0, 2 * np.pi, 50)\noffsets = np.linspace(0, 2 * np.pi, 8, endpoint=False)\nyy = np.transpose([np.sin(x + phi) for phi in offsets])\n\nfig = plt.figure(figsize=(10, 4))\nwith mpl.rc_context({\"axes.prop_cycle\": c1}):\n    ax1 = fig.add_subplot(3, 1, 1)\n    ax1.plot(yy)\n    ax1.set_title(\"changing_colors\")\n\nwith mpl.rc_context({\"axes.prop_cycle\": c1 + c2}):\n    ax2 = fig.add_subplot(3, 1, 2)\n    ax2.plot(yy)\n    ax2.set_title(\"changing linestyle and color\")\n\nwith mpl.rc_context({\"axes.prop_cycle\": c1 + c2 + c3}):\n    ax3 = fig.add_subplot(3, 1, 3)\n    ax3.plot(yy)\n    ax3.set_title(\"changing linestyle, color and marker\")\n\nplt.show()\n```\n\u003cimg src=\"https://raw.githubusercontent.com/anoopkcn/plotreset/refs/heads/main/examples/cycles.svg\" alt=\"cycles\" role=\"img\"\u003e\n\nYou can create your own templates and cycles and use them in the same way. (check the **Add more styles** section below for more details)\n\n### Example.3 script using the `rc_context`:\nChanging the style using dot notation(`style.font.size=10`) will change the plot settings in thje global scope but if you would like to change the settings for a specific plot you can use the `rc_context` method.\n\n```python\nimport matplotlib as mpl\nfrom plotreset import Styles\n\nstyle = Styles(\"academic\")\n\n# Create example data\nn = 30 * 75\np = 1 / 900\nx = np.array(range(0, 15))\n\ndef res(n, p, x):\n    return math.comb(n, x) * p**x * (1 - p) ** (n - x)\n\np_x = np.array([res(n, p, i) for i in x])\n\ncolor = [\"tab:blue\"] * len(x)\ncolor[0] = \"tab:orange\"\n\n# The default behavior of academic style is not to draw a grid on the axes.\n# We can change this behavior by using the `rc_context` method ...\n# ...so that this setting only affect this plot\nrc_context = {\"axes.grid\": True, \"axes.axisbelow\": True}\n\nwith mpl.rc_context(rc_context):\n    plt.bar(x, p_x, color=color)\n    plt.xticks(x)\n    plt.ylabel(\"$\\\\mathrm{P(X)}$\")\n    plt.xlabel(\"$\\\\mathrm{X}$\")\n    plt.annotate(\n        \"$\\\\mathrm{P(X=0) = 0.082}$\",\n        xy=(x.max() / 2.0, p_x.max() / 2),\n        ha=\"left\",\n        va=\"center\",\n    )\n    plt.annotate(\n        \"$\\\\mathrm{P(X\\\\geq1) = 0.918}$\",\n        xy=(x.max() / 2.0, p_x.max() / 2 - 0.03),\n        ha=\"left\",\n        va=\"center\",\n    )\n    plt.annotate(\n        \"$\\\\mathrm{E(X) = 2.49}$\",\n        xy=(x.max() / 2.0, p_x.max() / 2 - 0.06),\n        ha=\"left\",\n        va=\"center\",\n    )\nplt.show()\n```\n\u003cimg src=\"https://raw.githubusercontent.com/anoopkcn/plotreset/refs/heads/main/examples/binomial.svg\" alt=\"binomial\" role=\"img\"\u003e\n\n## Add more styles\n\nYou can add more styles in your scrit by creating a dictionary of style settings and call the `register_template` method to register the style.\n\n```python\nimport plotreset\nmy_template = {\n    \"axes.facecolor\": \"lightgray\",\n    \"font.size\": 14,\n    # ... other style settings\n}\nplotreset.register_template(\"my_custom_style\", my_template)\n\n# Use custom template\nstyles = Styles(\"my_custom_style\")\n```\n\n## Save and Load templates from a file\n\nYou can load custom templates from a JSON file and save the current template to a JSON file. When initializing the `Styles` object, you can specify the path to the JSON.\n\nThe JSON file for custom settings should have the following structure:\n```json\n{\n  \"templates\": {\n    \"style_name1\": {\n      // all the rc parameters as key-value pairs Ex: \"text.usetex\": true\n    }\n    \"style_name2\": {\n      // all the rc parameters as key-value pairs Ex: \"font.size\": 16,\n    }\n  }\n}\n```\nYou can give your style any name you want. But the **top level JSON key should be `templates`.**\n\n```python\nfrom plotreset import Styles\n\n# Load a custom style(style_name1) from a JSON file(custom_style_templates.json)\nstyle = Styles(\"style_name1\", \"path/to/custom_style_templates.json\")\n```\n\nYou can also save the current style to a JSON:\n```python\nstyle.save_current_template(\"my_new_style_name\", \"path/to/custom_style_templates.json\")\n```\nIf you sepecify `overwrite=True` in the `save_current_template` method and the same template name exist in the JSON file it will overwrite the template with updated style.\n\nHere is an example JSON file with custom templates(this is the same as `academic` style):\n```json\n{\n  \"templates\": {\n    \"academic\": {\n      \"text.usetex\": true,\n      \"mathtext.fontset\": \"cm\",\n      \"mathtext.fallback\": \"cm\",\n      \"mathtext.default\": \"regular\",\n      \"font.size\": 16,\n      \"font.family\": \"cmr10\",\n      \"axes.axisbelow\": \"line\",\n      \"axes.unicode_minus\": false,\n      \"axes.formatter.use_mathtext\": true,\n      \"axes.prop_cycle\": {\n        \"color\": [\n          \"tab:red\",\n          \"tab:blue\",\n          \"tab:green\",\n          \"tab:orange\",\n          \"tab:purple\",\n          \"tab:brown\",\n          \"tab:pink\",\n          \"tab:gray\",\n          \"tab:olive\",\n          \"tab:cyan\",\n          \"k\"\n        ]\n      },\n      \"axes.grid\": false,\n      \"grid.linewidth\": 0.6,\n      \"grid.alpha\": 0.5,\n      \"grid.linestyle\": \"--\",\n      \"xtick.top\": false,\n      \"xtick.direction\": \"in\",\n      \"xtick.minor.visible\": false,\n      \"xtick.major.size\": 6.0,\n      \"xtick.minor.size\": 4.0,\n      \"ytick.right\": false,\n      \"ytick.direction\": \"in\",\n      \"ytick.minor.visible\": false,\n      \"ytick.major.size\": 6.0,\n      \"ytick.minor.size\": 4.0,\n      \"figure.constrained_layout.use\": true\n    }\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanoopkcn%2Fplotreset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanoopkcn%2Fplotreset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanoopkcn%2Fplotreset/lists"}