{"id":19273914,"url":"https://github.com/ninivert/matplotlib_tufte","last_synced_at":"2025-02-23T20:45:14.053Z","repository":{"id":128920059,"uuid":"493810592","full_name":"ninivert/matplotlib_tufte","owner":"ninivert","description":"Styles from Tufte's \"Visual Display Of Quantitative Information\" for matplotlib","archived":false,"fork":false,"pushed_at":"2023-06-19T15:08:25.000Z","size":12535,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-05T14:28:17.722Z","etag":null,"topics":["matplotlib-styles","tufte"],"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/ninivert.png","metadata":{"files":{"readme":"README.rst","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}},"created_at":"2022-05-18T20:09:16.000Z","updated_at":"2024-11-03T11:57:23.000Z","dependencies_parsed_at":"2024-11-09T20:44:38.403Z","dependency_job_id":"700be44f-637f-4be4-a315-f1241c9746a7","html_url":"https://github.com/ninivert/matplotlib_tufte","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ninivert%2Fmatplotlib_tufte","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ninivert%2Fmatplotlib_tufte/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ninivert%2Fmatplotlib_tufte/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ninivert%2Fmatplotlib_tufte/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ninivert","download_url":"https://codeload.github.com/ninivert/matplotlib_tufte/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240378873,"owners_count":19792039,"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-styles","tufte"],"created_at":"2024-11-09T20:44:28.974Z","updated_at":"2025-02-23T20:45:09.036Z","avatar_url":"https://github.com/ninivert.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"``matplotlib-tufte`` -- styles from Tufte's \"Visual Display Of Quantitative Information\" for ``matplotlib``\n===========================================================================================================\n\n``matplotlib-tufte`` styles figures to make them easier on the eyes, and keep only essential ink.\n\nBased on : Tufte, Edward. `The Visual Display of Quantitative Information`. 2nd ed., Graphics Press, 2007.\n\n\nInstallation\n------------\n\n::\n\n\tpython -m pip install \"matplotlib_tufte @ git+https://github.com/ninivert/matplotlib_tufte.git\"\n\n\nUsage\n-----\n\n``setup`` tries to load the New Computer Modern font (comes packaged with ``matplotlib_tufte``) and the ``tufte.mplstyle`` stylesheet.\n\nChanges made by the custom style :\n\n* better readability using a serif font\n* New Computer Modern (used to be : Latin Modern Roman) font\n\n  * applied to all text (ticks, labels, legends, titles, etc.)\n  * in math mode, gives LaTeX-like math results, without needing a LaTeX installation\n\t\n* smaller figures (increase data density)\n\n  * figsize is defaulted to (4, 3)\n  * tight layout applied automatically\n\t\n* thinner axes to put emphasis on data ink\n\n* remove chartjunk and non-data ink\n\n  * remove top and right spines\n  * remove legend fancybox and frame\n\t\n* insert black as the first color of the cycler\n\nDocumentation for ``breathe``\n\n::\n\n\tAdd some space between the axes and the spines\n\n\tParameters\n\t----------\n\tax : matplotlib.axes.Axes\n\twhich : str or AxisWhich, optional\n\t\twhich axis to apply the spacing on, by default AxisWhich.BOTH\n\tpad_frac_start : float, optional\n\t\tspace to add to the start of the axis, as a fraction of the data span, by default 0.04\n\tpad_frac_end : float, optional\n\t\tspace to add to the end of the axis, as a fraction of the data span, by default 0.04\n\nDocumentation for ``data_lim``\n\n::\n\n\tSets the axis to use the limits of the data\n\n\tParameters\n\t----------\n\tax : matplotlib.axes.Axes\n\twhich : str or AxisWhich, optional\n\t\twhich axis to apply the spacing on, by default AxisWhich.BOTH\n\n\nIn other cases, you might just need to get your hands dirty, using methods such as\n\n- ``ax.spines.bottom.set_visible(False)`` to disable the bottom line\n- ``ax.set_xticks(...)`` and ``ax.set_xticklabels(...)`` to customize ticks\n- ``ax.set_xlim(...)`` and ``ax.set_xticklabels(...)`` to have nice integer limits. Use this in combination with ``breathe`` if you were used to matplotlib adding padding to the limits\n\n\nExamples\n--------\n\n`See also the demo notebook \u003cdemo/demo.ipynb\u003e`_\n\n::\n\n\tfrom matplotlib_tufte import *\n\tsetup()\n\timport matplotlib.pyplot as plt\n\timport matplotlib as mpl\n\timport numpy as np\n\n\tx = np.linspace(1, 9, 100)\n\ty1 = np.exp(-(x-2)) - np.sin(x-1) + 2\n\ty2 = 5 * 2/x * np.exp(-(np.log(x-0.99)-0.5)**2)\n\n\tplt.close('all')\n\tfig, ax = plt.subplots()\n\tax.set_xlabel('$x$')\n\tax.set_ylabel('$y$')\n\tax.plot(x, y1, label='data 1')\n\tax.plot(x, y2, label='data 2')\n\tax.legend()\n\tplt.show()\n\tfig.savefig('fig1.png')\n\n\n.. image:: demo/fig1.png\n\nLetting the axis breathe\n\n::\n\n\tbreathe(ax)\n\n\n.. image:: demo/fig2.png\n\nSetting data limits\n\n::\n\n\tdata_lim(ax)\n\n\n.. image:: demo/fig4.png\n\n\nGetting your hands dirty\n\n::\n\n\tnp.random.seed(0)\n\tN = 50\n\tsample1 = np.random.lognormal(0.9, 0.5, N)\n\tsample2 = np.random.lognormal(0.2, 0.7, N)\n\n\tmeans = [np.mean(sample1), np.mean(sample2)]\n\tstds = [np.std(sample1) * np.sqrt(N/(N-1)), np.std(sample2) * np.sqrt(N/(N-1))]  # sample stdev\n\tx = [0, 1]\n\n\tfig, ax = plt.subplots(figsize=(2, 3))\n\tfor x_, sample, m, s in zip(x, (sample1, sample2), means, stds):\n\t\tax.plot([x_]*len(sample), sample, linestyle='', marker='_', color='k')\n\t\tax.hlines(np.mean(sample), x_-0.3, x_+0.3, linewidth=0.5, color='k')\n\t\tax.add_patch(mpl.patches.FancyArrowPatch(\n\t\t\tarrowstyle='|-|,widthA=2.0,widthB=2.0',\n\t\t\tlinewidth=0.5,\n\t\t\tpath=mpl.path.Path([(x_-0.3, m-s), (x_-0.3, m+s)]))\n\t\t)\n\tax.set_xticks(x)\n\tax.set_xticklabels(['S1', 'S2'])\n\tax.set_xlim((-1, 2))\n\tax.set_ylim((0, 8))\n\tax.set_ylabel('measurement')\n\tbreathe(ax, 'y')\n\tax.spines.bottom.set_visible(False)\n\tplt.show()\n\n\n.. image:: demo/fig5.png\n\n\nIt is also possible to use ``matplotlib_tufte`` without using ``setup``\n\n::\n\n\t# demo/demo_nosetup.py\n\n\tfrom matplotlib_tufte import *\n\timport matplotlib.pyplot as plt\n\n\t# by default, will use gca\n\t# this is however discouraged\n\tplt.plot([0,1,2],[-2,4,5])\n\tdespine()\n\tdata_lim()\n\tbreathe()\n\tplt.savefig('fig_nosetup.png')\n\n\n.. image:: demo/fig_nosetup.png\n\n\nChangelog\n---------\n\nv0.2: changed default font from \"Latin Modern Roman\" to \"New Computer Modern\", which is more readable at smaller sizes.\n\n\nTODO\n----\n\n- Range frames\n- Data ticks\n- Axis histograms\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fninivert%2Fmatplotlib_tufte","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fninivert%2Fmatplotlib_tufte","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fninivert%2Fmatplotlib_tufte/lists"}