{ "info": { "author": "Alex Hagen", "author_email": "alexhagen6@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "\n# pyg - A graphics class\n\nBy Alex Hagen\n\n``pyg`` started as a simple wrapper around ``matplotlib`` to help me keep my style the same in plotting, but now it's expanded to a full graphics suite. If you get bored reading through the first two examples, skip to the bottom. Those examples are a bit cooler.\n\n## Installation\n\nFor ``pyg``, we need quite a few requirements. Installation right now is pretty manual, but this should do the trick on unix systems:\n\n```bash\npip install numpy scipy matplotlib colours\nmkdir ~/util\ncd ~/util\ngit clone https://github.com/alexhagen/pyg -b master pyg\nsudo echo \"export PYTHONPATH=${PYTHONPATH}:~/util\" >> ~/.bashrc\nsource ~/.bashrc\n```\n\nand then we can just import pyg whenever with\n\n\n```python\nfrom pyg import twod as pyg2d\n```\n\n## Usage\n\n``pyg`` has one main class, a ``twod`` plot type, and it has several other classes. The ``table`` module has some table printing help for Jupyter notebooks and some LaTeX publication helper functions. The ``threed`` module has some ``matplotlib`` three dimensional plotting (this is good for surface plotting, if you're doing geometric visualization, use my [``pyb``](github.com/alexhagen/pyb) class, which I'll include into ``pyg`` soon), ``three2twod`` is a class for annotating three dimensional plotting (if you have the transformation matrix from 3-d to 2-d). I've created some informative examples of these below. I've put interesting examples first, but they're a little complex. If you want to get started, skip to the \"[Boring Examples](#Boring-Examples)\" section.\n\n### Interesting Examples\n\n#### Three Dimensional Plotting\n\nThe following shows an example for 3d plotting using ``pyg``, which is generally simple except for the conversion from matrix data into a form that can be plotted. Below shows a simple example for a power fit, but an API is soon coming for converting data into the right formats.\n\n\n```python\nfrom pyg import threed as pyg3d\nimport numpy as np\n\nplot = pyg3d.pyg3d()\nx = np.linspace(0.0, 5.0)\ny = np.linspace(0.0, 5.0)\nX, Y = np.meshgrid(x, y)\nz = np.power(X, 2.0) - np.power(Y, 3.0)\nplot.surf(x, y, z)\nplot.export('_static/threed_surf')\nplot.show(caption='An arbitrary three dimensional surface')\n```\n\n\n\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
Figure 1: An arbitrary three dimensional surface
\n\t\t\t\t
\n\n\n\n#### Two to Three Dimensional Plotting\n\nThe description of 3 dimensional geometry by annotation is difficult in the best circumstances, but very few things are \"best circumstances\". Most of the field of visualization relies on software specifically designed for visualization, such as ``VTK`` and its derivatives. This is very powerful, but for someone analyzing data or writing simulations, the last thing they want to do is write an interface to these programs. So, I've written a quick and easy API to keep all the data in Python and visualize the geometry in Blender. Then, I have an interface for which the code can extract the camera parameters of an exported render, and then the user can plot two dimensional annotations overtop of the three-dimensional geometry, in place. A more advanced example is coming, but a rudimentary example is shown below.\n\n\n```python\nfrom pyg.pyb import pyb\nfrom pyg import three2twod as pyg32d\n\nscene = pyb.pyb()\nscene.rpp(c=(0., 0., 0.), l=(100., 100., 100.), name='cube')\nscene.flat(color='#fc8d82', name='newgold')\nscene.set_matl(obj='cube', matl='newgold')\nscene.rpp(c=(0., 0., -65.), l=(500., 500., 30.), name='floor')\nscene.flat(color='#888888', name='gray')\nscene.set_matl(obj='floor', matl='gray')\nscene.run('_static/blenderrender.png')\nplot = pyg32d.ann_im('_static/blenderrender.png')\nplot.add_data_pointer(0., 0., 0., string=r'$\\vec{c} = \\left( 0, 0, 0 \\right)$',\n place=(-500., 200.))\nplot.add_legend_entry(color='#fc8d82', name='Cube')\\\n .add_legend_entry(color='#888888', name='Floor')\nplot.legend(loc=2)\nplot.export('_static/ann_im', ratio='golden')\nplot.show('Using two dimensional annotations on a three dimensional geometric plot')\n```\n\n\n\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
Figure 2: Using two dimensional annotations on a three dimensional geometric plot
\n\t\t\t\t
\n\n\n\n#### Measurements\n\nOne thing I always hated about most plotting programs is how hard it is to add \"measurements\". These are so useful in calling out visual information that they're near universal in CAD, but in most plotting and other visualization, they're nowhere to be found. So, for the most part, I've included measurements in ``pyg``. The following example shows some measurements of grade distributions at IU's School of Medicine versus their nursing department. It shows how the distributions are clearly not normally distributed, but it also shows the grade inflation for the nursing department, with the overwhelming majority of classes giving A's, whereas the medical school fails a large proportion of students.\n\n\n```python\nfrom scipy.stats import gaussian_kde as gkde\n\ngrades = [4.0, 4.0, 3.7, 3.3, 3.0, 2.7, 2.3, 2.0, 1.7, 1.3, 1.0, 0.7, 0.0]\nmed = [51, 188, 84, 74, 141, 69, 54, 84, 45, 30, 51, 19, 53]\nnur = [228, 160, 89, 58, 77, 38, 17, 10, 1, 0, 0, 0, 0]\n\n_med = []\nfor m, g in zip(med, grades):\n _med += [g] * m\n\n_nur = []\nfor n, g in zip(nur, grades):\n _nur += [g] * n\n\nm_dist = gkde(_med)\nn_dist = gkde(_nur)\n\nsigma_m = np.std(_med)\nmu_m = np.mean(_med)\nsigma_n = np.std(_nur)\nmu_n = np.mean(_nur)\n\n_grades = np.linspace(0., 4.0)\n\nplot = pyg2d.pyg2d()\nplot.add_line(_grades, m_dist(_grades), linestyle='-', linecolor='#285668')\nplot.add_line(_grades, n_dist(_grades), linestyle='-', linecolor='#fc8d82')\nplot.add_hmeasure(mu_m + sigma_m, mu_m - sigma_m, 0.35, 'middle $2\\sigma$')\nplot.add_hmeasure(mu_n + sigma_n, mu_n - sigma_n, 1.5, 'middle $2\\sigma$')\nplot.xlabel(r'Grade ($g$) [$\\text{GPA Points}$]')\nplot.ylabel(r'Likelihood ($P$) [ ]')\nplot.lines_on()\nplot.markers_off()\n\nplot.export('_static/measure', ratio='silver')\nplot.show(caption='Depiction of useful measurements on a two-d plot')\n```\n\n\n\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
Figure 3: Depiction of useful measurements on a two-d plot
\n\t\t\t\t
\n\n\n\n### Boring Examples\n#### Line Plotting\n\nThe simplest plotting in ``pyg`` is line plotting, and the following two figures show the api for plotting a line with its associated uncertainty.\n\n\n```python\nx = np.linspace(0.0, 4.0 * np.pi, 1000)\ny = np.sin(x)\nu_y = 0.1\n\nplot = pyg2d.pyg2d()\nplot.add_line(x, y, linestyle='-', linecolor='#285668', yerr=u_y, error_fill=True,\n name=r'$\\sin \\left( \\theta \\right)$')\n\nplot.xlabel('x-coordinate ($x$) [$\\unit{cm}$]')\nplot.ylabel('y-coordinate ($y$) [$\\unit{cm}$]')\n\nplot.lines_on()\nplot.markers_off()\n\nplot.export('_static/line', ratio='silver')\nplot.show(caption='A line drawing with uncertainty in y')\n```\n\n\n\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
Figure 4: A line drawing with uncertainty in y
\n\t\t\t\t
\n\n\n\n\n```python\nx = np.linspace(0.0, 4.0 * np.pi, 1000)\ny = 5.0 * np.cos(x)\nu_y = 1.0\nx_sparse = np.linspace(0.0, 4.0 * np.pi, 10)\ny_sparse = 5.0 * np.cos(x_sparse)\nu_y_sparse = 1.0\n\nplot = pyg2d.pyg2d()\nplot.add_line(x, y, linestyle='-', linecolor='#fc8d82', yerr=u_y, error_fill=True,\n name=r'$\\sin \\left( \\theta \\right)$')\nplot.add_line(x_sparse, y_sparse, linecolor='#000000', yerr=u_y_sparse,\n name=r'sparse')\nplot.lines_on()\nplot.markers_off()\nplot.lines['sparse'].set_alpha(1.0)\nplot.lines['sparse'].set_markersize(6)\nplot.lines['sparse'].set_linewidth(0.0)\n\nplot.export('_static/err', ratio='silver')\nplot.show(caption='Sinusoid with uncertainty and a sparsely sampled sinusoid with uncertainty')\n```\n\n\n\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
Figure 5: Sinusoid with uncertainty and a sparsely sampled sinusoid with uncertainty
\n\t\t\t\t
\n\n\n\n#### Dual Axis Plotting\n\nThe following figure shows the API for plotting data on concurrent axes. There are two different APIs to this: the first requires you to plot your data, and then define a function that converts one axis to another. The other API requires you to plot two different data sets on axes with different limits.\n\n\n```python\nx = np.linspace(0., 4.0 * np.pi, 1000)\ny1 = 1.0 * np.sin(x)\ny2 = 5.0 * np.cos(x)\n\nplot = pyg2d.pyg2d()\nplot.add_line(x, y1, linecolor='#fc8d82', name='$y_{1}$')\nplot.add_line_yy(x, y2, linecolor='#285668', name='$y_{2}$')\nplot.markers_off()\n\nplot.xlabel('x coordinate ($x$)')\nplot.ylabel('y coordinate ($y_{1}$)')\nplot.ylabel('y coordinate ($y_{2}$)', axes=plot.ax2)\nplot.legend(loc=3)\n\nplot.export('_static/dual', ratio='silver')\nplot.show('Sinusoids with the same $x$ axis, on different $y$ axes')\n```\n\n\n\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
Figure 6: Sinusoids with the same $x$ axis, on different $y$ axes
\n\t\t\t\t
\n\n\n\nThe next figure shows how you can compare a single function against different ordinate axes. This would be useful if you are comparing different units, but I particularly use it when there is some electrical measurement that is calibrated non-linearly (for example, in gamma spectroscopy).\n\n\n```python\nx = np.linspace(0., 4.0 * np.pi, 1000)\ny = 1.0 * np.sin(x)\n\nplot = pyg2d.pyg2d()\nplot.add_line(x, y, linecolor='#285668', name='$y$')\nplot.markers_off()\n\ndef pi_div(x):\n return x / np.pi\nplot.add_xx(pi_div)\n\nplot.xlabel('x coordinate ($x$) [$\\unit{cm}$]')\nplot.xlabel('x coordinate in terms of $\\pi$ ($x$) [$\\unit{\\pi}$]', axes=plot.ax2)\nplot.ylabel('y coordinate ($y$) [$\\unit{cm}$]')\n\nplot.export('_static/dualx', ratio='silver')\nplot.show('Sinusoid in terms of radians and in terms of $\\pi$')\n```\n\n\n\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t
Figure 7: Sinusoid in terms of radians and in terms of $\\pi$
\n\t\t\t\t
\n\n\n\n## Coming Features and implementation details\n\n- SVG import for illustrating on charts\n\t- SVG addition via post processing - only suitable for SVG export (https://stackoverflow.com/questions/31452451/importing-an-svg-file-a-matplotlib-figure)[https://stackoverflow.com/questions/31452451/importing-an-svg-file-a-matplotlib-figure]\n\t- SVG conversion to matplotlib via regexing (https://matplotlib.org/examples/showcase/firefox.html)[https://matplotlib.org/examples/showcase/firefox.html]\n\n\n```python\n\n```\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/alexhagen/pyg", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pyg-plot", "package_url": "https://pypi.org/project/pyg-plot/", "platform": "", "project_url": "https://pypi.org/project/pyg-plot/", "project_urls": { "Homepage": "https://github.com/alexhagen/pyg" }, "release_url": "https://pypi.org/project/pyg-plot/0.0.1/", "requires_dist": [ "IPython", "matplotlib", "numpy", "colour", "itertools", "warnings", "pickle", "string", "os", "scipy", "copy", "time", "shutil" ], "requires_python": "", "summary": "High abstraction layer plotting with ``matplotlib``.", "version": "0.0.1" }, "last_serial": 4044617, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "8962780c3f4ee1b5c74511498c6b1cb0", "sha256": "9e067af10c12e8806b87eedf843240dad506808df0e824d4168221702c19b523" }, "downloads": -1, "filename": "pyg_plot-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8962780c3f4ee1b5c74511498c6b1cb0", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 44474, "upload_time": "2018-07-09T18:18:23", "url": "https://files.pythonhosted.org/packages/d9/0b/539cec04d590df69abb25972d5f69fa207830e7bdc9198ebacd4e6d851ed/pyg_plot-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6da91beb9d6e9524c912b14388606ce4", "sha256": "57da78da468cfc465ad65fa380f24c7343e0d2b4c8c4683836d257d9e0a98cd7" }, "downloads": -1, "filename": "pyg_plot-0.0.1.tar.gz", "has_sig": false, "md5_digest": "6da91beb9d6e9524c912b14388606ce4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 40975, "upload_time": "2018-07-09T18:18:24", "url": "https://files.pythonhosted.org/packages/e4/5a/3d745f23c2c7c3d9a8f34f14b39dbad8f4f36d67da9b01fd7118f4cd9da8/pyg_plot-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8962780c3f4ee1b5c74511498c6b1cb0", "sha256": "9e067af10c12e8806b87eedf843240dad506808df0e824d4168221702c19b523" }, "downloads": -1, "filename": "pyg_plot-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8962780c3f4ee1b5c74511498c6b1cb0", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 44474, "upload_time": "2018-07-09T18:18:23", "url": "https://files.pythonhosted.org/packages/d9/0b/539cec04d590df69abb25972d5f69fa207830e7bdc9198ebacd4e6d851ed/pyg_plot-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6da91beb9d6e9524c912b14388606ce4", "sha256": "57da78da468cfc465ad65fa380f24c7343e0d2b4c8c4683836d257d9e0a98cd7" }, "downloads": -1, "filename": "pyg_plot-0.0.1.tar.gz", "has_sig": false, "md5_digest": "6da91beb9d6e9524c912b14388606ce4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 40975, "upload_time": "2018-07-09T18:18:24", "url": "https://files.pythonhosted.org/packages/e4/5a/3d745f23c2c7c3d9a8f34f14b39dbad8f4f36d67da9b01fd7118f4cd9da8/pyg_plot-0.0.1.tar.gz" } ] }