{"id":16489513,"url":"https://github.com/erwanp/publib","last_synced_at":"2025-03-16T18:31:53.349Z","repository":{"id":55100351,"uuid":"47323532","full_name":"erwanp/publib","owner":"erwanp","description":"Produce publication-level quality images on top of Matplotlib","archived":false,"fork":false,"pushed_at":"2024-04-08T00:35:54.000Z","size":608,"stargazers_count":43,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-27T12:16:23.786Z","etag":null,"topics":["matplotlib","matplotlib-style-sheets","matplotlib-styles","plot","scientific-papers"],"latest_commit_sha":null,"homepage":null,"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/erwanp.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}},"created_at":"2015-12-03T10:01:57.000Z","updated_at":"2024-11-06T17:40:20.000Z","dependencies_parsed_at":"2022-08-14T12:00:32.908Z","dependency_job_id":null,"html_url":"https://github.com/erwanp/publib","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erwanp%2Fpublib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erwanp%2Fpublib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erwanp%2Fpublib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erwanp%2Fpublib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erwanp","download_url":"https://codeload.github.com/erwanp/publib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826783,"owners_count":20354220,"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":["matplotlib","matplotlib-style-sheets","matplotlib-styles","plot","scientific-papers"],"created_at":"2024-10-11T13:44:22.498Z","updated_at":"2025-03-16T18:31:52.027Z","avatar_url":"https://github.com/erwanp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PyPI version](https://badge.fury.io/py/publib.svg)](https://badge.fury.io/py/publib)\n[![Tests](https://img.shields.io/travis/erwanp/publib.svg)](https://travis-ci.org/erwanp/publib)\n[![Code coverage](https://codecov.io/gh/erwanp/publib/branch/master/graph/badge.svg)](https://codecov.io/gh/erwanp/publib)\n\n# Publib\n\n## Description\n\nProduce publication-level quality images on top of Matplotlib, with a \nsimple call to a couple functions at the start and end of your script. \n\n[Project GitHub page](https://github.com/erwanp/publib)\n\nFor similar librairies, see the [References section](https://github.com/erwanp/publib#references). \n\n## Install\n\n```\npip install publib\n```\n\n## Use\n\nAt the beginning of the script, call:\n\n``` {.sourceCode .python}\nset_style()\n```\n\nAfter each new axe is plotted, call:\n\n``` {.sourceCode .python}\nfix_style()\n```\n\nNote that importing publib will already load the basic style.\n\nA few more styles (`'poster'`, `'article'`, etc.) can be selected with the\nfunction `set_style()`\n\nBecause some matplotlib parameters cannot be changed before the lines\nare plotted, they are called through the function `fix_style()` which:\n\n-   changes the minor ticks\n\n-   remove the spines\n\n-   turn the legend draggable by default\n\n## Examples\n\n``` {.sourceCode .python}\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib as mpl\n```\n\nA default Matplotlib plot:\n\n``` {.sourceCode .python}\nmpl.rcdefaults()\n\nx = np.linspace(0,5,250)\ny = np.cos(x)**2+np.random.normal(scale=0.5,size=len(x))\nyav = np.cos(x)**2\nplt.figure()\nax = plt.subplot()\nax.plot(x,y,'o',label='normal distribution')\nax.plot(x,yav,zorder=-1,label='average')\nplt.xlabel(r'$x$')\nplt.ylabel(r'$\\cos^2 x$+noise')\nplt.title('matplotlib')\nplt.legend(loc='upper left')\nplt.ylim((-1.5,3.5))\nplt.show()\nplt.savefig('mpl_default.png')\n```\n\n![mpl_defaults.png](https://github.com/erwanp/publib/blob/master/docs/mpl_default.png)\n\nAnd now the same code with the two new lines calling the \npublib functions\n\n``` {.sourceCode .python}\nfrom publib import set_style, fix_style\nset_style('article')        # before the first plot\n\nx = np.linspace(0,5,250)\ny = np.cos(x)**2+np.random.normal(scale=0.5,size=len(x))\nyav = np.cos(x)**2\nplt.figure()\nax = plt.subplot()\nax.plot(x,y,'o',label='normal distribution')\nax.plot(x,yav,zorder=-1,label='average')\nplt.xlabel(r'$x$')\nplt.ylabel(r'$\\cos^2 x$+noise')\nplt.title('article')\nplt.legend(loc='upper left')\nplt.ylim((-1.5,3.5))\n\nfix_style('article')  # after the axe has been created\n\nplt.show()\nplt.savefig('publib_article.png')\n```\n\n![publib_article.png](https://github.com/erwanp/publib/blob/master/docs/publib_article.png)\n\nThe [OriginPro](https://www.originlab.com/Origin) style:\n\n```\nset_style('origin')\n\n...\n\nfix_style('origin')\n```\n\n![publib_origin.png](https://github.com/erwanp/publib/blob/master/docs/publib_origin.png)\n\nA combination of styles:\n\n```\nset_style(['poster', 'origin'])\n\n...\n\nfix_style(['poster', 'origin'])\n```\n\n![publib_poster_origin.png](https://github.com/erwanp/publib/blob/master/docs/publib_poster_origin.png)\n\nOr, assuming you have the Latin Modern Math font installed: \n\n```\nset_style(['origin', 'latex'])\n\n...\n\nfix_style(['origin', 'latex'])\n```\n\n![publib_origin_latex.png](https://github.com/erwanp/publib/blob/master/docs/publib_origin_latex.png)\n\n\n\n\n\nRun the test() routines in `publib.test` for more examples. \n\n\n## Tools\n\nThe publib.tools module include independant functions to fix some common matplotlib bugs, \nor include extra features. They're usually glanced from somewhere on the web. Proper  \nreferencing is made in the function docstrings. \n\nSee for instance:\n\n- `publib.tools.reset_defaults`: reset Matplotlib defaults \n\n- `publib.tools.regenerate_fonts`: rebuild Matplotlib font cache\n\n- `publib.tools.fix_bold_TimesNewRoman`: fix Times New Roman font appearing bold. See \n[StackOverflow](https://stackoverflow.com/questions/33955900/matplotlib-times-new-roman-appears-bold)\n\n- `publib.tools.keep_color`: apply the same color for the next graph to plot\n\n- `publib.tools.get_next_color`: see which color will be applied next in the color cycle state\n\n```\nplt.plot(...)\nkeep_color()\nplt.plot(...)\n```\n\n- `publib.tools.list_font_names`: to list all fonts available in Python. \n\n\nSee [tools.py](https://github.com/erwanp/publib/blob/master/publib/tools/__init__.py) \nfor more details\n\n## Changes\n\n- 0.2.2: added tools\n\n- 0.1.9: added talk and OriginPro style \n\n- 0.1.7 : default fonts to Times in article\n\n## References\n\nSome other interesting packages to make nice graphs in Matplotlib. \n\nAdd new features:\n\n- [pypdfplot](https://github.com/dcmvdbekerom/pypdfplot): embed the script within the pdf. One single file for the figure and the code!\n- [brokenaxes](https://github.com/bendichter/brokenaxes)\n- [matplotlib-tools](https://github.com/terranjp/matplotlib-tools): toolbar (ruler, etc.)\n\nStyle based:\n\n- the Matplotlib default [style feature](http://matplotlib.org/users/style_sheets.html)\n- [seaborn](http://stanford.edu/~mwaskom/software/seaborn/)\n- [prettyplotlib](https://github.com/olgabot/prettyplotlib)\n- [garrettj403](https://github.com/garrettj403)'s matplotlib styles for [ThesisPlot](https://github.com/garrettj403/ThesisPlots)\n\nTips and demos of Matplotlib:\n\n- [A great cheatsheet](https://nbviewer.jupyter.org/urls/gist.githubusercontent.com/Jwink3101/e6b57eba3beca4b05ec146d9e38fc839/raw/f486ca3dcad44c33fc4e7ddedc1f83b82c02b492/Matplotlib_Cheatsheet)\n  by [Jwink3101](https://github.com/Jwink3101)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferwanp%2Fpublib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferwanp%2Fpublib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferwanp%2Fpublib/lists"}