{ "info": { "author": "Caleb Fangmeier", "author_email": "caleb@fangmeier.tech", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Topic :: Internet :: WWW/HTTP :: Site Management", "Topic :: Software Development :: Documentation", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Text Processing :: Markup :: HTML" ], "description": "\n\n[](https://travis-ci.com/cfangmeier/matplotboard)\n\nA utility to generate html dashboards using matplotlib. Matplotboard makes it easy to\nwrap your plotting functions and dump the plots into a searchable webpage or a markdown report. This is best\ndemonstrated with an example.\n\n\n``` python\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotboard as mpb\n\n@mpb.decl_fig\ndef cool_fig():\n xs = np.linspace(-10, 10, 100)\n ys = xs**2\n plt.plot(xs, ys)\n\nif __name__ == '__main__':\n figures = {\n 'cool_fig': cool_fig(),\n }\n\n mpb.render(figures)\n mpb.generate_report(figures, 'Report')\n```\nYou can view the results [here](https://cfangmeier.github.io/matplotboard/example_01/dashboard/report.html). Let's walk through this one part at a time.\n\nFirst, we import `numpy` and `matplotlib` for some calculations, and plotting,\nrespectively. As well as `matplotboard` itself.\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotboard as mpb\n```\n\n\n`matplotboard` relies upon `matplotlib` for the underlying rendering engine so\nother plotting libraries are not supported. However, wrappers around\n`matplotlib` such as `seaborn` should work.\n\nNext, we declare the function that is actually going to do the plotting.\n\n```python\n@mpb.decl_fig\ndef cool_fig():\n xs = np.linspace(-10,10, 100)\n ys = xs**2\n plt.plot(xs, ys)\n```\n\nThe `decl_fig` decorator modifies the function to work with `matplotboard`. A\nplotting function decorated with `decl_fig` must fulfill the following\ncontract:\n\n - A clean `figure` has been initiated and the function will do any plotting\n on that figure.\n - It is free to subdivide the figure into as many axes as required, but\n shouldn't create additional `Figure` objects.\n - The function can optionally return Markdown text that will be rendered\n along with the plot.\n - The function shouldn't call `savefig`. This is handled by `matplotboard`\n automatically.\n\nFinally, we declare the actual figures that we want to generate, and tell `matplotboard` to render the figures and assemble them into an interactive webpage.\n\n```python\nif __name__ == '__main__':\n figures = {\n 'cool_fig': cool_fig(),\n }\n\n mpb.render(figures)\n mpb.generate_report(figures, 'Report')\n```\n\nBoth `render`, and `generate_report` take a dictionary as their first argument.\nThe dictionary keys are strings that are interpreted as the individual figure\nnames, and the dictionary values are the plots we want to generate. Note that\nthe function is called before inserting it into the dictionary. Due to the \nmodification of the original function by the decorator, this doesn't actually\ncall the function yet, but bundles the function and any arguments together\ninto a `Figure` object which it then returns for later processing by `matplotboard`.\n\nBy writing plotting functions with arguments, a single function can be reused\nto make many different plots. For example, you may have a dataset that is\ndivided into several categories and you would like to plot some variable for\neach category. You could do this by writing one plotting function and calling\nit with different arguments to specify each of the categories.\n\nTry running the example. If everything works, there should be a new folder in\nthe current directory called `dashboard`, and within it an html file called\n`report.html`. Open it with your browser to see a dashboard containing a single\nplot. Try clicking on it for a zoomed view!\n\nA single plot is not very interesting. Where `matplotboard` starts to really become useful is when you have lots of plots to generate. Check out the following example.\n\n```python\nfrom itertools import product\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotboard as mpb\n\n@mpb.decl_fig\ndef cool_fig(func, scale, color='b'):\n xs = np.linspace(-scale, scale, 100)\n f = {\n 'sin': lambda xs: np.sin(xs),\n 'tan': lambda xs: np.tan(xs),\n 'exp': lambda xs: np.exp(xs),\n }[func]\n ys = f(xs)\n plt.plot(xs, ys, color=color)\n\nif __name__ == '__main__':\n mpb.configure(multiprocess=True)\n figures = {}\n\n for color, function, scale in product('rbgk', ['sin', 'tan', 'exp'], np.linspace(1, 20, 20)):\n figures[f'{function}_{color}_{scale}'] = cool_fig(function, scale, color=color)\n\n\n mpb.render(figures)\n mpb.generate_report(figures, 'Report')\n```\n\nWhat's changed? You can view the page [here](https://cfangmeier.github.io/matplotboard/example_02/dashboard/report.html)\n\nFirst of all, the plotting function has been enhanced to take a few arguments\nthat modify it's behavior. You can now specify whether you would like to plot\n`sin`, `tan`, or `exp` as well as effectively set the x length scale.\n\nSecond, we now are programatically making all combinations of plotting color,\nfunction, and scale with the `product` function and declaring a plot for each\ncombination. This comes down to `4*3*20=240` different plots. To speed things\nup a bit, this example also switches on `matplotboard`'s multiprocessing\nsupport. Try running this example and open up the resulting web-page just as\nbefore. Note the pagination feature limiting the number of figures displayed at\nonce. Also, try selecting a plot and moving through the figures on the page\nwith the arrow keys. Finally, try out the filter box in the top right. A few\ninteresting searches may be \"sin\\_\", \"\\_r\\_\", or \"tan\\_g\\_9\" to search for all\n`sin` plots, all red plots, and just the `tan_g_9` plot, respectively.\n\nFor one final example, let's look at the support for writing reports the incorporate generated figures.\n\n```python\n\nfrom itertools import product\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotboard as mpb\n\n\n@mpb.decl_fig\ndef cool_fig(func, scale, color=\"b\"):\n xs = np.linspace(-scale, scale, 100)\n f = {\n \"sin\": lambda xs: np.sin(xs),\n \"tan\": lambda xs: np.tan(xs),\n \"exp\": lambda xs: np.exp(xs),\n }[func]\n ys = f(xs)\n plt.plot(xs, ys, color=color)\n\n\nreport = \"\"\"\\\nAuthors: Will Hunting\nDate: December 2, 1997\n\n# Report On Functions\n\n## Introduction\n\nAs we all know, there are many functions. An example is the sine function seen below.\nfig::sin_b_1\n\n## Other Functions\n\nHowever, there are many other functions such as the tangent or exponential.\n\n