py-gnuplot


Namepy-gnuplot JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttp://www.gnuplot.info
Summarypy-gnuplot is a python plot tools based on gnuplot.
upload_time2024-02-06 15:46:30
maintainer
docs_urlNone
authorYongping Guo
requires_python>=3.6
licenseGPLv3
keywords gnuplot pandas
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. meta::
   :description: gnuplot plotting backend for python.
   :keywords: gnuplot, py-gnuplot, pandas, python, plot

Gnuplot is a powerful command-line driven graphing utility for many platforms.
To leverage the powful gnuplot to plot beautiful image in efficicent way in
python, we port gnuplot to python. 

We develop **set()/unset()** function to set or unset gnuplot plotting style,
**plot()/splot()** to operate gnuplot plot or splot command, **cmd()** to
execute any commands that coulnd't be done by the above functions. They are
intuative and gnuplot users can swith to py-gnuplot naturally. By this means we
can do what gnuplot do.

.. image:: https://gnuplot.sourceforge.net/demo_6.0/transparent.2.png
    :align: right
    :width: 300

But for plotting python generated data the above functions are not enough. We
develop **plot_data()/splot_data()** to plot data generated in
python.

Here is a quick examples to generate the right image with only basic functions,
more examples which plot python generated data are coming in later sections.

.. _sphinx-plot-directive: https://pypi.org/project/sphinx-plot-directive

.. _quick_example.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot

    #py-gnuplot: A quick demo

    #Ceate a gnuplot context. with "log = True" to print the gnuplot execute log.
    g = gnuplot.Gnuplot(log = True)

    #Set plotting style
    g.set(terminal = 'pngcairo transparent enhanced font "arial,8" fontscale 1.0 size 512, 280 ',
            output = '"quick_example.png"',
            style = ["fill transparent solid 0.50 noborder", "data lines", "function filledcurves y1=0"],
            key = 'title "Gaussian Distribution" center fixed left top vertical Left reverse enhanced autotitle nobox noinvert samplen 1 spacing 1 width 0 height 0',
            title = '"Transparent filled curves"',
            xrange = '[ -5.00000 : 5.00000 ] noreverse nowriteback',
            yrange = '[ 0.00000 : 1.00000 ] noreverse nowriteback')

    #Expressions and caculations
    g.cmd('Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )',
            'd1(x) = Gauss(x, 0.5, 0.5)',
            'd2(x) = Gauss(x,  2.,  1.)',
            'd3(x) = Gauss(x, -1.,  2.)')

    #Plotting
    g.plot('d1(x) fs solid 1.0 lc rgb "forest-green" title "μ =  0.5 σ = 0.5"',
            'd2(x) lc rgb "gold" title "μ =  2.0 σ = 1.0"',
            'd3(x) lc rgb "dark-violet" title "μ = -1.0 σ = 2.0"')

more examples:

.. _simple.1.gnu: http://gnuplot.sourceforge.net/demo/simple.1.gnu
.. _surface2.9.gnu: http://gnuplot.sourceforge.net/demo/surface2.9.gnu
.. _histograms.1.gnu: http://gnuplot.sourceforge.net/demo/histograms.1.gnu
.. _iterate.2.gnu: http://gnuplot.sourceforge.net/demo/iterate.2.gnu
.. _finance.13.gnu: http://gnuplot.sourceforge.net/demo/finance.13.gnu

.. |simple.1.png| image:: http://gnuplot.sourceforge.net/demo/simple.1.png
   :width: 350
.. |surface2.9.png| image:: http://gnuplot.sourceforge.net/demo/surface2.9.png
   :width: 350
.. |finance.13.png| image:: http://gnuplot.sourceforge.net/demo/finance.13.png
   :width: 350
.. |iterate.2.png| image:: http://gnuplot.sourceforge.net/demo/iterate.2.png
   :width: 350
.. |whale.png| image:: http://ayapin-film.sakura.ne.jp/Gnuplot/Pm3d/Part1/whale.png
   :width: 350
.. |histograms.2.png| image:: http://gnuplot.sourceforge.net/demo/histograms.2.png
   :width: 350
.. |sphx_glr_bar_stacked_001.png| image:: https://matplotlib.org/_images/sphx_glr_bar_stacked_001.png
   :width: 350
.. |sphx_glr_barchart_001.png| image:: https://matplotlib.org/_images/sphx_glr_barchart_001.png
   :width: 350
.. |sphx_glr_axes_demo_001.png| image:: https://matplotlib.org/_images/sphx_glr_axes_demo_001.png
   :width: 350
.. |sphx_glr_pie_features_0011.png| image:: https://matplotlib.org/_images/sphx_glr_pie_features_0011.png
   :width: 350
.. |sphx_glr_tex_demo_001.png| image:: https://matplotlib.org/_images/sphx_glr_tex_demo_001.png
   :width: 350
.. |sphx_glr_axes_margins_001.png| image:: https://matplotlib.org/_images/sphx_glr_axes_margins_001.png
   :width: 350

.. list-table:: Table1 : plot examples with different script

   * - examples
     - plot function
     - plot file
     - splot function
     - splot file
     - multiplot
   * - figure
     - |simple.1.png|
     - |histograms.2.png|
     - |surface2.9.png|
     - |whale.png|
     - |finance.13.png|
   * - gnuplot script
     - `simple.1.gnu`_
     - `histograms.1.gnu`_
     - `surface2.9.gnu`_
     - `iterate.2.gnu`_
     - `finance.13.gnu`_
   * - py-gnuplot script
     - `simple.1.py`_
     - `histograms.2.py`_
     - `surface.9.py`_
     - `whale.py`_
     - `finance.13.py`_
   * - py-gnuplot quick mode
     - `simple2.1.py`_
     - `histograms2.2.py`_
     - `surface2.9.py`_
     - `whale2.py`_
     -  N/A(too complicated)
   * - py-gnuplot data generated in python
     - N/A
     - `histograms3.2.py`_
     - N/A
     - N/A
     - `finance3.13.py`_

.. list-table:: Table2 : examples porting from matplotlib
   :widths: 30,30,30

   * - `sphx_glr_bar_stacked_001.py`_ |sphx_glr_bar_stacked_001.png|
     - `sphx_glr_barchart_001.py`_ |sphx_glr_barchart_001.png|
     - `sphx_glr_axes_demo_001.py`_ |sphx_glr_axes_demo_001.png|
   * - `sphx_glr_axes_margins_001.py`_ |sphx_glr_axes_margins_001.png|
     - `sphx_glr_tex_demo_001.py`_ |sphx_glr_tex_demo_001.png|
     - `sphx_glr_pie_features_0011.py`_ |sphx_glr_pie_features_0011.png|

Let's see the detail.

.. contents:: [Contents]
   :depth: 2

1. Introduction
=================

As we know, to plot a image in gnuplot we do:

    1) Enter gnuplot conext;
    2) Set plotting style;
    3) Define some expressions;
    4) Plotting.

We translate gnuplot's main function into python ones, and each one do the same
thing as gnuplot. As in `quick_example.py`_ we also have 4 steps to plot an
image::

    #Constructor
    g = gnuplot.Gnuplot()
    #Set plotting style
    g.set()
    #Expressions and caculations
    g.cmd()
    #Plotting
    g.plot()

1.1 constructor
----------------

Defenition:

.. code-block:: python

    def __init__(self, *args, log = False, **kwargs):
        '''
        *args: The flag parameter in gnuplot
        log: If print the gnuplot log
        **kwargs: the flag that need to be set. You can also set them in the set() function.
        '''

We call g = gnuplot.Gnuplot(log = True) to get a gnuplot context. Here log = True means to print the gnuplot log when call gnuplot functions.::

    #Ceate a gnuplot context. with "log = True" to print the gnuplot execute log.
    g = gnuplot.Gnuplot(log = True)

1.2 Set()/unset()
------------------

Defenition:

.. code-block:: python

    def set(self, *args, **kwargs):
        '''
        *args: options without value
        *kwargs: options with value. The set and unset commands may optionally
                 contain an iteration clause, so the arg could be list.
        '''
    def unset(self, *items):
        '''
        *args: options that need to be unset
        '''

After enter gnuplot context, normally we need to set the plotting style. For
example we need to set the terminal and output at first in gnuplt as following::

    set terminal pngcairo  transparent enhanced font "arial,8" fontscale 1.0 size 512, 280 
    set output 'transparent.2.png'

Then we translate the set into set() function as following, please not that all
the elment are stirng, so must add extra quoto and it would be passed to
gnuplot without any change. Pleae note that all the parameters must be string
since it would be passed to gnuplot without any change. You need to change them
to string if they are not::

    #Set plotting style
    g.set(terminal = 'pngcairo transparent enhanced font "arial,8" fontscale 1.0 size 512, 280 ',
            output = '"quick_example.png"',
            ...
            )

For unset we have flexible ways to do that, for exampes the following ways are
the same::

    #gnuplot unset
    unset colorbox

    #py-gnuplot means1
    g.unset(colorbox)

    #py-gnuplot means2
    g.set(colorbox = None)

    #py-gnuplot means3
    g.set(nocolorbox = "")

1.3 cmd()
----------

Defenition:

.. code-block:: python

    def cmd(self, *args):
        '''
        *args: all the line that need to pass to gnuplot. It could be a
        list of lines, or a paragraph; Lines starting with "#" would be
        omitted. Every line should be a clause that could be executed in
        gnuplot.
        '''

Sometimes before plot we need define some variable or caculations, call cmd() functions to do::

    #gnuplot
    Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )
    d1(x) = Gauss(x, 0.5, 0.5)
    d2(x) = Gauss(x,  2.,  1.)
    d3(x) = Gauss(x, -1.,  2.)

    #py-gnuplot
    g.cmd('Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )',
            'd1(x) = Gauss(x, 0.5, 0.5)',
            'd2(x) = Gauss(x,  2.,  1.)',
            'd3(x) = Gauss(x, -1.,  2.)')

As we see, all statement in cmd() would be translated the same statement in
gnuplot. By this way we can execute any gnuplot statement.

1.4 plot()/splot()
------------------

Definition:

.. code-block:: python

    def plot(self, *items, **kwargs):
        '''
        *items: The list of plot command;
        **kwargs: The options that would be set before the plot command.
        '''
    def splot(self, *items, **kwargs):
        '''
        *items: The list of plot command;
        **kwargs: The options that would be set before the plot command.
        '''

Every plot/splot command would be a parameter in plot()/splot() functions. Like
set()/unset(), all the parameters must be string since it would be pas sed to
gnuplot without any change. You need to change them to string if they are not::

    #gnplot
    plot d1(x) fs solid 1.0 lc rgb "forest-green" title "μ =  0.5 σ = 0.5", \
     d2(x) lc rgb "gold" title "μ =  2.0 σ = 1.0", \
     d3(x) lc rgb "dark-violet" title "μ = -1.0 σ = 2.0"

    #py-gnplot
    g.plot('d1(x) fs solid 1.0 lc rgb "forest-green" title "μ =  0.5 σ = 0.5"',
            'd2(x) lc rgb "gold" title "μ =  2.0 σ = 1.0"',
            'd3(x) lc rgb "dark-violet" title "μ = -1.0 σ = 2.0"')

1.5 plot_data()/splot_data()
--------------------------------------

.. Note:: in older release, they are called plot_data()/splot_data(), I'd like to chnage them to the new name since they are more intuitive.

Definition:

.. code-block:: python

    def plot_data(self, data, *items, **kwargs):
        '''
        data: The data that need to be plotted. It's either the string of list
        or the Pnadas Dataframe, if it's Pnadas Dataframe it would be converted
        to string by data.to_csv(). Note that we will execut a extra command
        "set datafile separator "," to fit the data format of csv.
        *items: The list of plot command;
        **kwargs: The options that would be set before the plot command.
        '''
    def splot_data(self, data, *items, **kwargs):
        '''
        data: The data that need to be plotted. It's either the string of list
        or the Pnadas Dataframe, if it's Pnadas Dataframe it would be converted
        to string by data.to_csv(). Note that we will execut a extra command
        "set datafile separator "," to fit the data format of csv.
        *items: The list of plot command;
        **kwargs: The options that would be set before the plot command.
        '''

With above functions: constructor, Set()/unset(), plot()/splot(), we can do
what gnuplot do, but it cannot plot python generated data. It's hard to
implement the new functions with the existing gnuplot command, so we develop
two new functions: plot_data()/splot_data(). They are much like
plot()/splot(), the only difference is:

    * plot()/splot() take function(filename) in every plot command.
    * plot_data()/splot_data() take the dataframe as the first
      parameter, while remove function(filename) in every plot commmand

for examples::

    #plot(): 'finance.dat' is in plot command
    g.plot("'finance.dat' using 0:($6/10000) notitle with impulses lt 3",
           "'finance.dat' using 0:($7/10000) notitle with lines lt 1")

    #plot_data(): the first parameter must be dataframe, every plot
    #command doesn't take the data.
    g.plot_data(df,
            'using 0:($6/10000) notitle with impulses lt 3',
            'using 0:($7/10000) notitle with lines lt 1')

See `histograms.2.py`_ and `histograms.2.py`_ for differences.

1.6 multiplot
------------------

To plot multiplot, you must set multiplot at first as in gnuplot. Here is examples.

1.7 quick mode
------------------

For some easy case, we can combine the following step into one.

    1) Enter gnuplot conext;
    2) Set plotting style;
    3) Define some expressions;
    4) Plotting.

For examples:

.. _simple2.1.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot

    gnuplot.plot('[-10:10] sin(x)',
           'atan(x)',
           'cos(atan(x))',
           terminal = 'pngcairo font "arial,10" fontscale 1.0 size 600, 400',
           output = '"simple.1.png"',
           key = 'fixed left top vertical Right noreverse enhanced autotitle box lt black linewidth 1.000 dashtype solid',
           samples = '50, 50',
           title = '"Simple Plots" font ",20" textcolor lt -1 norotate',
           xrange = '[ * : * ] noreverse writeback',
           x2range = '[ * : * ] noreverse writeback',
           yrange = '[ * : * ] noreverse writeback',
           y2range = '[ * : * ] noreverse writeback',
           zrange = '[ * : * ] noreverse writeback',
           cbrange = '[ * : * ] noreverse writeback',
           rrange = '[ * : * ] noreverse writeback',
           colorbox = 'vertical origin screen 0.9, 0.2 size screen 0.05, 0.6 front noinvert bdefault')

.. _whale2.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd

    #https://ayapin-film.sakura.ne.jp/Gnuplot/Pm3d/Part1/whale.html
    gnuplot.splot('"examples/whale.dat" w pm3d',
            term = 'pngcairo size 480,480',
            out = '"whale.png"',
            style = 'line 100 lw 0.1 lc "black"',
            pm3d = 'depth hidden3d ls 100',
            cbrange = '[-0.5:0.5]',
            palette = 'rgb -3,-3,-3',
            colorbox = None,
            border = None,
            key = None,
            zrange = '[-2:2]',
            tics = None,
            view = '60,185,1.5')

.. _histograms2.2.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd

    df = pd.read_csv('examples/immigration.dat', index_col = 0, sep='\t', comment='#')
    gnuplot.plot_data(df,
            'using 2:xtic(1), for [i=3:22] "" using i ',
            terminal = 'pngcairo transparent enhanced font "arial,10" fontscale 1.0 size 600, 400 ',
            output = '"histograms.1.png"',
            key = 'fixed right top vertical Right noreverse noenhanced autotitle nobox',
            style = 'data linespoints',
            datafile = ' missing "-"',
            xtics = 'border in scale 1,0.5 nomirror rotate by -45 autojustify norangelimit',
            title = '"US immigration from Europe by decade"')

.. _surface2.9.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot

    #py-gnuplot: https://gnuplot.sourceforge.net/demo/surface2.9.gnu
    gnuplot.splot('cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with lines',
            '1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with lines',
            terminal = 'pngcairo enhanced font "arial,10" fontscale 1.0 size 600, 400 ',
            output = '"surface2.9.png"',
            dummy = 'u, v',
            key = 'bmargin center horizontal Right noreverse enhanced autotitle nobox',
            style = ['data lines'],
            parametric = '',
            view = '50, 30, 1, 1',
            isosamples = '50, 20',
            hidden3d = 'back offset 1 trianglepattern 3 undefined 1 altdiagonal bentover',
            xyplane = 'relative 0',
            title = '"Interlocking Tori" ',
            urange = '[ -3.14159 : 3.14159 ] noreverse nowriteback',
            vrange = '[ -3.14159 : 3.14159 ] noreverse nowriteback')

2. Examples
=============

2.1 plot/splot function
-------------------------------

.. _simple.1.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot

    #py-gnuplot: https://gnuplot.sourceforge.net/demo_6.0/simple.html

    #Ceate a gnuplot context. with "log = True" to print the gnuplot execute log.
    g = gnuplot.Gnuplot(log = True)

    #Set plotting style
    g.set(terminal = 'pngcairo font "arial,10" fontscale 1.0 size 600, 400',
           output = '"simple.1.png"',
           key = 'fixed left top vertical Right noreverse enhanced autotitle box lt black linewidth 1.000 dashtype solid',
           samples = '50, 50',
           title = '"Simple Plots" font ",20" textcolor lt -1 norotate',
           xrange = '[ * : * ] noreverse writeback',
           x2range = '[ * : * ] noreverse writeback',
           yrange = '[ * : * ] noreverse writeback',
           y2range = '[ * : * ] noreverse writeback',
           zrange = '[ * : * ] noreverse writeback',
           cbrange = '[ * : * ] noreverse writeback',
           rrange = '[ * : * ] noreverse writeback',
           colorbox = 'vertical origin screen 0.9, 0.2 size screen 0.05, 0.6 front  noinvert bdefault')

    #Expressions and caculations
    g.cmd("NO_ANIMATION = 1")

    #Plotting
    g.plot("[-10:10] sin(x)", "atan(x)", "cos(atan(x))")

This is the output: 

|simple.1.png|

.. _surface.9.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot

    #py-gnuplot: https://gnuplot.sourceforge.net/demo_6.0/simple.html

    #Ceate a gnuplot context. with "log = True" to print the gnuplot execute log.
    g = gnuplot.Gnuplot(log = True)

    #Set plotting style
    g.set(terminal = 'pngcairo  transparent enhanced font "arial,10" fontscale 1.0 size 600, 400',
            output = "'surface2.9.png'",
            dummy = 'u, v',
            key = 'bmargin center horizontal Right noreverse enhanced autotitle nobox',
            parametric = '',
            view = '50, 30, 1, 1',
            isosamples = '50, 20',
            hidden3d = 'back offset 1 trianglepattern 3 undefined 1 altdiagonal bentover',
            style = ['data lines'],
            xyplane = 'relative 0',
            title = '"Interlocking Tori" ',
            urange = '[ -3.14159 : 3.14159 ] noreverse nowriteback',
            vrange = '[ -3.14159 : 3.14159 ] noreverse nowriteback',
            colorbox = 'vertical origin screen 0.9, 0.2 size screen 0.05, 0.6 front  noinvert bdefault')

    #Expressions and caculations
    g.cmd("NO_ANIMATION = 1")

    #Plotting
    g.splot("cos(u)+.5*cos(u)*cos(v)",
            "sin(u)+.5*sin(u)*cos(v)",
            ".5*sin(v) with lines",
            "1+cos(u)+.5*cos(u)*cos(v)",
            ".5*sin(v),sin(u)+.5*sin(u)*cos(v) with lines",
            )

This is the output: 

|surface2.9.png|

2.2 plot/splot file
-------------------------------

.. _histograms.2.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd

    #Histograms demo example comes from
    #https://gnuplot.sourceforge.net/demo_6.0/histograms.2.gnu

    #1) Ceate a gnuplot context
    g = gnuplot.Gnuplot(log = True)

    #2) Set plotting style
    g.set(terminal = 'pngcairo  transparent enhanced font "arial,10" fontscale 1.0 size 600, 400',
            output = "'histograms.2.png'",
            boxwidth = '0.9 absolute',
            style = ['fill   solid 1.00 border lt -1',
                'histogram clustered gap 1 title textcolor lt -1',
                'data histograms' ],
            key = 'fixed right top vertical Right noreverse noenhanced autotitle nobox',
            datafile = "missing '-'",
            xtics = ["border in scale 0,0 nomirror rotate by -45  autojustify",
                "norangelimit ",
                " ()"],
            title = '"US immigration from Northern Europe\\nPlot selected data columns as histogram of clustered boxes"',
            xrange = '[ * : * ] noreverse writeback',
            x2range = '[ * : * ] noreverse writeback',
            yrange  = '[ 0.00000 : 300000. ] noreverse writeback',
            y2range = '[ * : * ] noreverse writeback',
            zrange = '[ * : * ] noreverse writeback',
            cbrange = '[ * : * ] noreverse writeback',
            rrange = '[ * : * ] noreverse writeback',
            colorbox = 'vertical origin screen 0.9, 0.2 size screen 0.05, 0.6 front  noinvert bdefault')

    #3) Expressions and caculations
    g.cmd("NO_ANIMATION = 1")

    #4) Plotting
    g.plot("'examples/immigration.dat' using 6:xtic(1) ti col",
            "'' u 12 ti col",
            "'' u 13 ti col",
            "'' u 14 ti col")

This is the output: 

|histograms.2.png|

Another example is to splot a pm3d image:

.. _whale.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot

    #Whale example comes from
    #https://ayapin-film.sakura.ne.jp/Gnuplot/Pm3d/Part1/whale.html

    #Ceate a gnuplot context
    g = gnuplot.Gnuplot(log = True)

    #Set plotting style
    g.set(term = 'pngcairo size 480,480',
            output = '"whale.png"',
            style = 'line 100 lw 0.1 lc "black"',
            pm3d = 'depth hidden3d ls 100',
            cbrange = '[-0.5:0.5]',
            palette = 'rgb -3,-3,-3',
            colorbox = None,
            border   = None,
            key = None,
            zrange = '[-2:2]',
            tics  = None,
            view = '60,185,1.5')

    #No Expressions

    #Plotting
    g.splot('"examples/whale.dat" w pm3d')

The generated image is as below:

|whale.png|

2.3 plot/splot python generated data
----------------------------------------------

.. _histograms3.2.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd

    #Histograms demo example comes from
    #https://gnuplot.sourceforge.net/demo_6.0/histograms.2.gnu

    #1) Ceate a gnuplot context
    g = gnuplot.Gnuplot(log = True)

    #2) Set plotting style
    g.set(terminal = 'pngcairo  transparent enhanced font "arial,10" fontscale 1.0 size 600, 400',
            output = "'histograms.2.png'",
            boxwidth = '0.9 absolute',
            style = ['fill   solid 1.00 border lt -1',
                'histogram clustered gap 1 title textcolor lt -1',
                'data histograms' ],
            key = 'fixed right top vertical Right noreverse noenhanced autotitle nobox',
            datafile = "missing '-'",
            xtics = ["border in scale 0,0 nomirror rotate by -45  autojustify",
                "norangelimit ",
                " ()"],
            title = '"US immigration from Northern Europe\\nPlot selected data columns as histogram of clustered boxes"',
            xrange = '[ * : * ] noreverse writeback',
            x2range = '[ * : * ] noreverse writeback',
            yrange  = '[ 0.00000 : 300000. ] noreverse writeback',
            y2range = '[ * : * ] noreverse writeback',
            zrange = '[ * : * ] noreverse writeback',
            cbrange = '[ * : * ] noreverse writeback',
            rrange = '[ * : * ] noreverse writeback',
            colorbox = 'vertical origin screen 0.9, 0.2 size screen 0.05, 0.6 front  noinvert bdefault')

    #3) Expressions and caculations
    g.cmd("NO_ANIMATION = 1")
    #The original example is plotting file, it's easy. To demonstrate plotting
    #data generated in python, we transform the data into df for demonstration.
    df = pd.read_csv('examples/immigration.dat', index_col = 0, sep='\t', comment='#')

    #4) Plotting
    g.plot_data(df,
            'using 6:xtic(1) ti col',
            'u 12 ti col',
            'u 13 ti col',
            'u 14 ti col')

The generated image is as below:

|histograms.2.png|

2.4 multiplot examples
------------------------------

.. _finance.13.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd

    #Transparent demo example comes from
    #https://gnuplot.sourceforge.net/demo_6.0/finance.html

    #Ceate a gnuplot context
    g = gnuplot.Gnuplot(log = True)

    #Set plotting style
    g.set(output = "'finance.13.png'",
            term = 'pngcairo  transparent enhanced font "arial,8" fontscale 1.0 size 660, 320',
            label = ['1 "Acme Widgets" at graph 0.5, graph 0.9 center front',
                '2 "Courtesy of Bollinger Capital" at graph 0.01, 0.07',
                '3 "  www.BollingerBands.com" at graph 0.01, 0.03'],
            logscale = 'y',
            yrange = '[75:105]',
            ytics = '(105, 100, 95, 90, 85, 80)',
            xrange = '[50:253]',
            grid = '',
            lmargin = '9',
            rmargin = '2',
            format = 'x ""',
            xtics = '(66, 87, 109, 130, 151, 174, 193, 215, 235)',
            multiplot = True)

    #3) Expressions and caculations

    #4) Plotting: Since multiplot = True, we plot two subplot
    g.plot("'finance.dat' using 0:2:3:4:5 notitle with candlesticks lt 8",
            "'finance.dat' using 0:9 notitle with lines lt 3",
            "'finance.dat' using 0:10 notitle with lines lt 1",
            "'finance.dat' using 0:11 notitle with lines lt 2",
            "'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4",
            title = '"Change to candlesticks"',
            size = ' 1, 0.7',
            origin = '0, 0.3',
            bmargin = '0',
            ylabel = '"price" offset 1')
    g.plot("'finance.dat' using 0:($6/10000) notitle with impulses lt 3",
            "'finance.dat' using 0:($7/10000) notitle with lines lt 1",
            bmargin = '',
            format = ['x', 'y "%1.0f"'],
            size = '1.0, 0.3',
            origin = '0.0, 0.0',
            tmargin = '0',
            nologscale = 'y',
            autoscale = 'y',
            ytics = '500',
            xtics = '("6/03" 66, "7/03" 87, "8/03" 109, "9/03" 130, "10/03" 151, "11/03" 174, "12/03" 193, "1/04" 215, "2/04" 235)',
            ylabel = '"volume (0000)" offset 1')

.. _finance3.13.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd

    #Transparent demo example comes from
    #https://gnuplot.sourceforge.net/demo_6.0/finance.html

    #Ceate a gnuplot context
    g = gnuplot.Gnuplot(log = True)

    #Set plotting style
    g.set(output = "'finance.13.png'",
            term = 'pngcairo  transparent enhanced font "arial,8" fontscale 1.0 size 660, 320',
            label = ['1 "Acme Widgets" at graph 0.5, graph 0.9 center front',
                '2 "Courtesy of Bollinger Capital" at graph 0.01, 0.07',
                '3 "  www.BollingerBands.com" at graph 0.01, 0.03'],
            logscale = 'y',
            yrange = '[75:105]',
            ytics = '(105, 100, 95, 90, 85, 80)',
            xrange = '[50:253]',
            grid = '',
            lmargin = '9',
            rmargin = '2',
            format = 'x ""',
            xtics = '(66, 87, 109, 130, 151, 174, 193, 215, 235)',
            multiplot = True)

    #3) Expressions and caculations
    #A demostration to generate pandas data frame data in python.
    df = pd.read_csv('examples/finance.dat',
            sep='\t',
            index_col = 0,
            parse_dates = True,
            names = ['date', 'open','high','low','close', 'volume','volume_m50',
                'intensity','close_ma20','upper','lower '])

    #4) Plotting: Since multiplot = True, we plot two subplot
    g.plot_data(df,
            'using 0:2:3:4:5 notitle with candlesticks lt 8',
            'using 0:9 notitle with lines lt 3',
            'using 0:10 notitle with lines lt 1',
            'using 0:11 notitle with lines lt 2',
            'using 0:8 axes x1y2 notitle with lines lt 4',
            title = '"Change to candlesticks"',
            size = ' 1, 0.7',
            origin = '0, 0.3',
            bmargin = '0',
            ylabel = '"price" offset 1')
    g.plot_data(df,
            'using 0:($6/10000) notitle with impulses lt 3',
            'using 0:($7/10000) notitle with lines lt 1',
            bmargin = '',
            format = ['x', 'y "%1.0f"'],
            size = '1.0, 0.3',
            origin = '0.0, 0.0',
            tmargin = '0',
            nologscale = 'y',
            autoscale = 'y',
            ytics = '500',
            xtics = '("6/03" 66, "7/03" 87, "8/03" 109, "9/03" 130, "10/03" 151, "11/03" 174, "12/03" 193, "1/04" 215, "2/04" 235)',
            ylabel = '"volume (0000)" offset 1')

Both script generate the same output image:

|finance.13.png|

2.5 Examples port from matplotlib
-----------------------------------

Just for fun, I translate some examples in matplotlib to py-gnuplot:

2.5.1 Stacked bar chart
+++++++++++++++++++++++

.. _sphx_glr_bar_stacked_001.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd

    # data is from https://matplotlib.org/gallery/lines_bars_and_markers/bar_stacked.html#sphx-glr-gallery-lines-bars-and-markers-bar-stacked-py
    #https://matplotlib.org/_downloads/2ac62a2edbb00a99e8a853b17387ef14/bar_stacked.py
    labels = ['G1', 'G2', 'G3', 'G4', 'G5']
    men_means = [20, 35, 30, 35, 27]
    women_means = [25, 32, 34, 20, 25]
    men_std = [2, 3, 4, 1, 2]
    women_std = [3, 5, 2, 3, 3]
    width = 0.35       # the width of the bars: can also be len(x) sequence

    # Plot programme:
    df = pd.DataFrame({'men_means': men_means,
        'women_means': women_means,
        'men_std': men_std,
        'women_std': women_std}, index = labels)
    #print(df)
    gnuplot.plot_data(df,
            'using :($2 + $3):5:xtic(1) with boxerror title "women" lc "dark-orange"',
            'using :2:4 with boxerror title "men" lc "royalblue"',
            style = ['data boxplot', 'fill solid 0.5 border -1'],
            boxwidth = '%s' %(width),
            xrange = '[0.5:5.5]',
            ylabel = '"Scores"',
            title = '"Scores by group and gender"',
            output = '"sphx_glr_bar_stacked_001.png"',
            terminal = 'pngcairo size 640, 480')

This is the output:

|sphx_glr_bar_stacked_001.png|

2.5.2 Grouped bar chart with labels
+++++++++++++++++++++++++++++++++++

.. _sphx_glr_barchart_001.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd

    # data is from https://matplotlib.org/gallery/lines_bars_and_markers/barchart.html#sphx-glr-gallery-lines-bars-and-markers-barchart-py
    labels = ['G1', 'G2', 'G3', 'G4', 'G5']
    men_means = [20, 34, 30, 35, 27]
    women_means = [25, 32, 34, 20, 25]
    width = 0.35  # the width of the bars

    # Plot programme:
    df = pd.DataFrame({'men': men_means, 'women': women_means},
            index = labels)
    df.index.name = 'label'
    #print(df)
    gnuplot.plot_data(df,
            'using 2:xticlabels(1) title columnheader(2) lc "web-blue"',
            'using 3:xticlabels(1) title columnheader(3) lc "orange"',
            'using ($0-0.2):($2+1):2 with labels notitle column',
            'using ($0+0.2):($3+1):3 with labels notitle column',
            title = '"Scores by group and gender"',
            xrange = '[-0.5:4.5]',
            yrange = '[0:38]',
            ylabel = '"Scores"',
            style = ['data histogram',
                     'histogram cluster gap 1',
                     'fill solid border -1',
                     'textbox transparent'],
            output = '"sphx_glr_barchart_001.png"',
            terminal = 'pngcairo size 640, 480')

This is the output:

|sphx_glr_barchart_001.png|

2.5.3 Multiplot Axes Demo
+++++++++++++++++++++++++

.. _sphx_glr_axes_demo_001.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd
    import numpy as np

    #https://matplotlib.org/gallery/subplots_axes_and_figures/axes_demo.html#sphx-glr-gallery-subplots-axes-and-figures-axes-demo-py
    #http://gnuplot.sourceforge.net/demo_5.2/bins.html

    # 1) create some data to use for the plot
    np.random.seed(19680801) # Fixing random state for reproducibility
    dt = 0.001
    t = np.arange(0.0, 10.0, dt)
    r = np.exp(-t / 0.05)  # impulse response
    x = np.random.randn(len(t))
    s = np.convolve(x, r)[:len(x)] * dt  # colored noise
    df = pd.DataFrame({'r': r, 'x': x, 's': s}, index = t)
    df.index.name = 't'

    g = gnuplot.Gnuplot(log = True,
            output = '"sphx_glr_axes_demo_001.png"',
            term = 'pngcairo font "arial,10" fontscale 1.0 size 640, 480',
            key = '',
            multiplot = True)

    # 2) Plot the data
    g.plot_data(df.iloc[:1000],
            'using 1:4 with line lw 2 lc "web-blue"',
            title = '"Gaussian colored noise"',
            xlabel = '"time (s)"',
            ylabel = '"current (nA)"',
            xrange = '[0:1]',
            yrange = '[-0.015:0.03]',
            key = None,
            size = ' 1, 1',
            origin = '0, 0')
    g.plot_data(df,
            'using 4 bins=400 with boxes title "20 bins" lw 2 lc "web-blue"',
            title = '"Probability"',
            xlabel = None,
            ylabel = None,
            tics = None,
            xrange = None,
            yrange = None,
            origin = '0.65, 0.56',
            size = '0.24, 0.32',
            object = 'rectangle from graph 0,0 to graph 1,1 behind fc "black" fillstyle solid 1.0')
    g.plot_data(df,
            'using 1:2 with line lw 2 lc "web-blue"',
            title = '"Impulse response"',
            xrange = '[0:0.2]',
            origin = '0.15, 0.56',
            size = '0.24, 0.32')

This is the output:

|sphx_glr_axes_demo_001.png|

2.5.4 control view and zoom 
++++++++++++++++++++++++++++

.. _sphx_glr_axes_margins_001.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd

    #https://matplotlib.org/gallery/subplots_axes_and_figures/axes_margins.html#sphx-glr-gallery-subplots-axes-and-figures-axes-margins-py
    g = gnuplot.Gnuplot(log = True,
            output = '"sphx_glr_axes_margins_001.png"',
            term = 'pngcairo font "arial,10" fontscale 1.0 size 640,480',
            multiplot = True)

    g.cmd('f(x) = exp(-x) * cos(2*pi*x)')
    g.plot('sample [x=0:3] "+" using (x):(f(x)) with lines',
            title = '"Zoomed out"',
            key = None,
            xrange = '[-6: 9]',
            yrange = '[-4: 4]',
            xtics = '-5, 5, 5',
            ytics = '-2, 2, 4',
            origin = '0, 0.5',
            size = '0.5, 0.5')
    g.plot('f(x)',
            title = '"Zoomed in"',
            key = None,
            xrange = '[0: 3]',
            yrange = '[-0.2: 0.5]',
            xtics = '0, 1, 2',
            ytics = '-0.2, 0.2, 0.4',
            origin = '0.5, 0.5',
            size = '0.5, 0.5')
    g.plot('f(x)',
            title = None,
            key = None,
            xrange = '[0: 3]',
            yrange = '[-0.7: 1]',
            xtics = '0, 0.5, 3',
            ytics = '-0.5, 0.5, 1',
            origin = '0, 0',
            size = '1, 0.5')

This is the output:

|sphx_glr_axes_margins_001.png|

2.5.5 Rendering math equation using TeX
+++++++++++++++++++++++++++++++++++++++

We can embed the TeX math equation into the gnuplot generated image by setting
the epslatex terminal, it would be rendered as a .tex file, you can import it
directly or you can convert it to .pdf file and then .png file if needed. this
is the example:

.. _sphx_glr_tex_demo_001.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd

    # https://matplotlib.org/gallery/text_labels_and_annotations/tex_demo.html#sphx-glr-gallery-text-labels-and-annotations-tex-demo-py
    # http://wap.sciencenet.cn/blog-373392-500657.html
    # https://www.thinbug.com/q/17593917
    g = gnuplot.Gnuplot(log = True,
            output = '"sphx_glr_tex_demo_001.tex"',
            term = 'epslatex standalone lw 2 color colortext')

    # NOTE: In the following example, we need to escape the "\", that means we
    # should use '\\' or "\\\\" for \
    g.plot('cos(4*pi*x) + 2',
            xlabel = "'\\textbf{time (s)}'",
            ylabel = "'\\textit{Velocity (\N{DEGREE SIGN}/sec)}'",
            title = "'\\TeX\\ is Number $\\displaystyle\\sum_{n=1}^\\infty\\frac{-e^{i\\pi}}{2^n}$!' tc 'red'",
            key = None,
            xrange = '[0: 1]')

This is the output:

|sphx_glr_tex_demo_001.png|

I list the script output since it's with the log=True::

    [py-gnuplot 14:56:13] set output "sphx_glr_tex_demo_001.tex"
    [py-gnuplot 14:56:13] set term epslatex standalone lw 2 color colortext
    [py-gnuplot 14:56:13] set xlabel '\textbf{time (s)}'
    [py-gnuplot 14:56:13] set ylabel '\textit{Velocity (°/sec)}'
    [py-gnuplot 14:56:13] set title '\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!' tc 'red'
    [py-gnuplot 14:56:13] unset key
    [py-gnuplot 14:56:13] set xrange [0: 1]
    [py-gnuplot 14:56:13] plot cos(4*pi*x) + 2

2.5.6 Basic pie chart
+++++++++++++++++++++

.. _sphx_glr_pie_features_0011.py:
.. code-block:: python

    #!/usr/bin/env python3
    #coding=utf8
    from pygnuplot import gnuplot
    import pandas as pd
    import math

    #http://www.phyast.pitt.edu/~zov1/gnuplot/html/pie.html
    #https://matplotlib.org/gallery/pie_and_polar_charts/pie_features.html#sphx-glr-gallery-pie-and-polar-charts-pie-features-py
    # Pie chart, where the slices will be ordered and plotted counter-clockwise:
    labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
    sizes = [15, 30, 45, 10]
    explode = (0, 0.1, 0, 0)  # only "explode" the 2nd slice (i.e. 'Hogs')
    startangle = math.pi/2

    # Prepare the data: caculate the percentage
    df = pd.DataFrame({'labels': labels, 'sizes': sizes, 'explode': explode})
    df.index.name = 'index'
    df['percentage'] = df['sizes'] / df['sizes'].sum()
    df['end'] = df['percentage'].cumsum()*2*math.pi + startangle
    #df['start'] = df['end'].shift(axis=0, fill_value = 0)
    df['start'] = df['end'].shift(axis=0)
    df = df.fillna(startangle)
    #print(df)

    pie_shade = []
    pie_graph = []

    shade_offset = 0.03
    g = gnuplot.Gnuplot(log = True,
            output = '"sphx_glr_pie_features_0011.png"',
            term = 'pngcairo size 640, 480',
            key = None,
            parametric = "",
            border = "",
            tics = "",
            multiplot = True)

    for k, v in df.iterrows():
        #print(k,v)
        cos = math.cos((v['start']+v['end'])/2)
        sin = math.sin((v['start']+v['end'])/2)

        # If we'd like explode the piece, ad the dx/dy to move the origi point.
        dx = v['explode'] * cos
        dy = v['explode'] * sin

        # make the shade for each piece
        g.plot('cos(t)+%f, sin(t)+%f with filledcurves xy=%f,%f lc "grey80"'
                %(dx-shade_offset, dy-shade_offset, dx-shade_offset, dy-shade_offset),
                trange = '[%f:%f]' %(v['start'], v['end']),
                xrange = '[-1.5:1.5]',
                yrange = '[-1.5:1.5]')

        # make the pie and label
        g.plot('cos(t)+%f, sin(t)+%f with filledcurve xy=%f,%f  lt %d'
                %(dx, dy, dx, dy, k+3),
                trange = '[%f:%f]' %(v['start'], v['end']),
                xrange = '[-1.5:1.5]',
                yrange = '[-1.5:1.5]',
                label = ['1 "%s" at %f, %f center front' %(v['labels'], 1.2*cos+dx, 1.2*sin+dy), '2 "%.1f%%" at %f, %f center front' %(v['percentage']*100, 0.6*cos, 0.6*sin)])

This is the output:

|sphx_glr_pie_features_0011.png|

3. Q/A
=======

4. CHANGLOG
=============

1.0 Initial upload;

1.0.3 Now Gnuplot().plot()/splot() supplot set options as parameters.

1.0.7 The pyplot.plot() now can accept both string and pandas.Dataframe as the
first parameter, Further more we need pandas installed at first.

1.0.11 Fix the bug: gnuplot.multiplot() doesn't work.

1.0.15 1) Add an example of comparing the object-oriented interface call and
global class-less function call in multiplot() in multiplot() in
multiplot() in multiplot(). 2) remove some duplicate setting line.

1.0.19 Add a log options to enable the log when run the script.

1.1 Upgrade to 1.1: 1) Submodule pyplot is depreciated. 2) To plot python generated
data we use gnuplot.plot_data() and gnuplot.splot_data().


1.1.2 Enhancement: If it's multiplot mode, automatically call the following
Gnuplot to unset the label:

    g.unset('for [i=1:200] label i')

1.1.3 Enhancement: When plotting the python generated data, we set the
seperator to "," for easy using it in csv file.

1.1.5 Bug fix: on some case it exit exceptionally.

1.1.8 Remove some Chinese comments to remove the "UnicodeDecodeError" for some users.

1.1.9 1) Run and update the examples in gnuplot6.0.0. 2) If you'd like enable multiplot, you shuld use  multimplot = True to replace multimplot = "".

1.1.13 Document update.



            

Raw data

            {
    "_id": null,
    "home_page": "http://www.gnuplot.info",
    "name": "py-gnuplot",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "gnuplot,pandas",
    "author": "Yongping Guo",
    "author_email": "guoyoooping@163.com",
    "download_url": "https://files.pythonhosted.org/packages/00/58/03f817c95458cc51c3340c025bda3417e7e645576f4738496d8b6d3bd680/py-gnuplot-1.2.0.tar.gz",
    "platform": null,
    "description": ".. meta::\n   :description: gnuplot plotting backend for python.\n   :keywords: gnuplot, py-gnuplot, pandas, python, plot\n\nGnuplot is a powerful command-line driven graphing utility for many platforms.\nTo leverage the powful gnuplot to plot beautiful image in efficicent way in\npython, we port gnuplot to python. \n\nWe develop **set()/unset()** function to set or unset gnuplot plotting style,\n**plot()/splot()** to operate gnuplot plot or splot command, **cmd()** to\nexecute any commands that coulnd't be done by the above functions. They are\nintuative and gnuplot users can swith to py-gnuplot naturally. By this means we\ncan do what gnuplot do.\n\n.. image:: https://gnuplot.sourceforge.net/demo_6.0/transparent.2.png\n    :align: right\n    :width: 300\n\nBut for plotting python generated data the above functions are not enough. We\ndevelop **plot_data()/splot_data()** to plot data generated in\npython.\n\nHere is a quick examples to generate the right image with only basic functions,\nmore examples which plot python generated data are coming in later sections.\n\n.. _sphinx-plot-directive: https://pypi.org/project/sphinx-plot-directive\n\n.. _quick_example.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n\n    #py-gnuplot: A quick demo\n\n    #Ceate a gnuplot context. with \"log = True\" to print the gnuplot execute log.\n    g = gnuplot.Gnuplot(log = True)\n\n    #Set plotting style\n    g.set(terminal = 'pngcairo transparent enhanced font \"arial,8\" fontscale 1.0 size 512, 280 ',\n            output = '\"quick_example.png\"',\n            style = [\"fill transparent solid 0.50 noborder\", \"data lines\", \"function filledcurves y1=0\"],\n            key = 'title \"Gaussian Distribution\" center fixed left top vertical Left reverse enhanced autotitle nobox noinvert samplen 1 spacing 1 width 0 height 0',\n            title = '\"Transparent filled curves\"',\n            xrange = '[ -5.00000 : 5.00000 ] noreverse nowriteback',\n            yrange = '[ 0.00000 : 1.00000 ] noreverse nowriteback')\n\n    #Expressions and caculations\n    g.cmd('Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )',\n            'd1(x) = Gauss(x, 0.5, 0.5)',\n            'd2(x) = Gauss(x,  2.,  1.)',\n            'd3(x) = Gauss(x, -1.,  2.)')\n\n    #Plotting\n    g.plot('d1(x) fs solid 1.0 lc rgb \"forest-green\" title \"\u03bc =  0.5 \u03c3 = 0.5\"',\n            'd2(x) lc rgb \"gold\" title \"\u03bc =  2.0 \u03c3 = 1.0\"',\n            'd3(x) lc rgb \"dark-violet\" title \"\u03bc = -1.0 \u03c3 = 2.0\"')\n\nmore examples:\n\n.. _simple.1.gnu: http://gnuplot.sourceforge.net/demo/simple.1.gnu\n.. _surface2.9.gnu: http://gnuplot.sourceforge.net/demo/surface2.9.gnu\n.. _histograms.1.gnu: http://gnuplot.sourceforge.net/demo/histograms.1.gnu\n.. _iterate.2.gnu: http://gnuplot.sourceforge.net/demo/iterate.2.gnu\n.. _finance.13.gnu: http://gnuplot.sourceforge.net/demo/finance.13.gnu\n\n.. |simple.1.png| image:: http://gnuplot.sourceforge.net/demo/simple.1.png\n   :width: 350\n.. |surface2.9.png| image:: http://gnuplot.sourceforge.net/demo/surface2.9.png\n   :width: 350\n.. |finance.13.png| image:: http://gnuplot.sourceforge.net/demo/finance.13.png\n   :width: 350\n.. |iterate.2.png| image:: http://gnuplot.sourceforge.net/demo/iterate.2.png\n   :width: 350\n.. |whale.png| image:: http://ayapin-film.sakura.ne.jp/Gnuplot/Pm3d/Part1/whale.png\n   :width: 350\n.. |histograms.2.png| image:: http://gnuplot.sourceforge.net/demo/histograms.2.png\n   :width: 350\n.. |sphx_glr_bar_stacked_001.png| image:: https://matplotlib.org/_images/sphx_glr_bar_stacked_001.png\n   :width: 350\n.. |sphx_glr_barchart_001.png| image:: https://matplotlib.org/_images/sphx_glr_barchart_001.png\n   :width: 350\n.. |sphx_glr_axes_demo_001.png| image:: https://matplotlib.org/_images/sphx_glr_axes_demo_001.png\n   :width: 350\n.. |sphx_glr_pie_features_0011.png| image:: https://matplotlib.org/_images/sphx_glr_pie_features_0011.png\n   :width: 350\n.. |sphx_glr_tex_demo_001.png| image:: https://matplotlib.org/_images/sphx_glr_tex_demo_001.png\n   :width: 350\n.. |sphx_glr_axes_margins_001.png| image:: https://matplotlib.org/_images/sphx_glr_axes_margins_001.png\n   :width: 350\n\n.. list-table:: Table1 : plot examples with different script\n\n   * - examples\n     - plot function\n     - plot file\n     - splot function\n     - splot file\n     - multiplot\n   * - figure\n     - |simple.1.png|\n     - |histograms.2.png|\n     - |surface2.9.png|\n     - |whale.png|\n     - |finance.13.png|\n   * - gnuplot script\n     - `simple.1.gnu`_\n     - `histograms.1.gnu`_\n     - `surface2.9.gnu`_\n     - `iterate.2.gnu`_\n     - `finance.13.gnu`_\n   * - py-gnuplot script\n     - `simple.1.py`_\n     - `histograms.2.py`_\n     - `surface.9.py`_\n     - `whale.py`_\n     - `finance.13.py`_\n   * - py-gnuplot quick mode\n     - `simple2.1.py`_\n     - `histograms2.2.py`_\n     - `surface2.9.py`_\n     - `whale2.py`_\n     -  N/A(too complicated)\n   * - py-gnuplot data generated in python\n     - N/A\n     - `histograms3.2.py`_\n     - N/A\n     - N/A\n     - `finance3.13.py`_\n\n.. list-table:: Table2 : examples porting from matplotlib\n   :widths: 30,30,30\n\n   * - `sphx_glr_bar_stacked_001.py`_ |sphx_glr_bar_stacked_001.png|\n     - `sphx_glr_barchart_001.py`_ |sphx_glr_barchart_001.png|\n     - `sphx_glr_axes_demo_001.py`_ |sphx_glr_axes_demo_001.png|\n   * - `sphx_glr_axes_margins_001.py`_ |sphx_glr_axes_margins_001.png|\n     - `sphx_glr_tex_demo_001.py`_ |sphx_glr_tex_demo_001.png|\n     - `sphx_glr_pie_features_0011.py`_ |sphx_glr_pie_features_0011.png|\n\nLet's see the detail.\n\n.. contents:: [Contents]\n   :depth: 2\n\n1. Introduction\n=================\n\nAs we know, to plot a image in gnuplot we do:\n\n    1) Enter gnuplot conext;\n    2) Set plotting style;\n    3) Define some expressions;\n    4) Plotting.\n\nWe translate gnuplot's main function into python ones, and each one do the same\nthing as gnuplot. As in `quick_example.py`_ we also have 4 steps to plot an\nimage::\n\n    #Constructor\n    g = gnuplot.Gnuplot()\n    #Set plotting style\n    g.set()\n    #Expressions and caculations\n    g.cmd()\n    #Plotting\n    g.plot()\n\n1.1 constructor\n----------------\n\nDefenition:\n\n.. code-block:: python\n\n    def __init__(self, *args, log = False, **kwargs):\n        '''\n        *args: The flag parameter in gnuplot\n        log: If print the gnuplot log\n        **kwargs: the flag that need to be set. You can also set them in the set() function.\n        '''\n\nWe call g = gnuplot.Gnuplot(log = True) to get a gnuplot context. Here log = True means to print the gnuplot log when call gnuplot functions.::\n\n    #Ceate a gnuplot context. with \"log = True\" to print the gnuplot execute log.\n    g = gnuplot.Gnuplot(log = True)\n\n1.2 Set()/unset()\n------------------\n\nDefenition:\n\n.. code-block:: python\n\n    def set(self, *args, **kwargs):\n        '''\n        *args: options without value\n        *kwargs: options with value. The set and unset commands may optionally\n                 contain an iteration clause, so the arg could be list.\n        '''\n    def unset(self, *items):\n        '''\n        *args: options that need to be unset\n        '''\n\nAfter enter gnuplot context, normally we need to set the plotting style. For\nexample we need to set the terminal and output at first in gnuplt as following::\n\n    set terminal pngcairo  transparent enhanced font \"arial,8\" fontscale 1.0 size 512, 280 \n    set output 'transparent.2.png'\n\nThen we translate the set into set() function as following, please not that all\nthe elment are stirng, so must add extra quoto and it would be passed to\ngnuplot without any change. Pleae note that all the parameters must be string\nsince it would be passed to gnuplot without any change. You need to change them\nto string if they are not::\n\n    #Set plotting style\n    g.set(terminal = 'pngcairo transparent enhanced font \"arial,8\" fontscale 1.0 size 512, 280 ',\n            output = '\"quick_example.png\"',\n            ...\n            )\n\nFor unset we have flexible ways to do that, for exampes the following ways are\nthe same::\n\n    #gnuplot unset\n    unset colorbox\n\n    #py-gnuplot means1\n    g.unset(colorbox)\n\n    #py-gnuplot means2\n    g.set(colorbox = None)\n\n    #py-gnuplot means3\n    g.set(nocolorbox = \"\")\n\n1.3 cmd()\n----------\n\nDefenition:\n\n.. code-block:: python\n\n    def cmd(self, *args):\n        '''\n        *args: all the line that need to pass to gnuplot. It could be a\n        list of lines, or a paragraph; Lines starting with \"#\" would be\n        omitted. Every line should be a clause that could be executed in\n        gnuplot.\n        '''\n\nSometimes before plot we need define some variable or caculations, call cmd() functions to do::\n\n    #gnuplot\n    Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )\n    d1(x) = Gauss(x, 0.5, 0.5)\n    d2(x) = Gauss(x,  2.,  1.)\n    d3(x) = Gauss(x, -1.,  2.)\n\n    #py-gnuplot\n    g.cmd('Gauss(x,mu,sigma) = 1./(sigma*sqrt(2*pi)) * exp( -(x-mu)**2 / (2*sigma**2) )',\n            'd1(x) = Gauss(x, 0.5, 0.5)',\n            'd2(x) = Gauss(x,  2.,  1.)',\n            'd3(x) = Gauss(x, -1.,  2.)')\n\nAs we see, all statement in cmd() would be translated the same statement in\ngnuplot. By this way we can execute any gnuplot statement.\n\n1.4 plot()/splot()\n------------------\n\nDefinition:\n\n.. code-block:: python\n\n    def plot(self, *items, **kwargs):\n        '''\n        *items: The list of plot command;\n        **kwargs: The options that would be set before the plot command.\n        '''\n    def splot(self, *items, **kwargs):\n        '''\n        *items: The list of plot command;\n        **kwargs: The options that would be set before the plot command.\n        '''\n\nEvery plot/splot command would be a parameter in plot()/splot() functions. Like\nset()/unset(), all the parameters must be string since it would be pas sed to\ngnuplot without any change. You need to change them to string if they are not::\n\n    #gnplot\n    plot d1(x) fs solid 1.0 lc rgb \"forest-green\" title \"\u03bc =  0.5 \u03c3 = 0.5\", \\\n     d2(x) lc rgb \"gold\" title \"\u03bc =  2.0 \u03c3 = 1.0\", \\\n     d3(x) lc rgb \"dark-violet\" title \"\u03bc = -1.0 \u03c3 = 2.0\"\n\n    #py-gnplot\n    g.plot('d1(x) fs solid 1.0 lc rgb \"forest-green\" title \"\u03bc =  0.5 \u03c3 = 0.5\"',\n            'd2(x) lc rgb \"gold\" title \"\u03bc =  2.0 \u03c3 = 1.0\"',\n            'd3(x) lc rgb \"dark-violet\" title \"\u03bc = -1.0 \u03c3 = 2.0\"')\n\n1.5 plot_data()/splot_data()\n--------------------------------------\n\n.. Note:: in older release, they are called plot_data()/splot_data(), I'd like to chnage them to the new name since they are more intuitive.\n\nDefinition:\n\n.. code-block:: python\n\n    def plot_data(self, data, *items, **kwargs):\n        '''\n        data: The data that need to be plotted. It's either the string of list\n        or the Pnadas Dataframe, if it's Pnadas Dataframe it would be converted\n        to string by data.to_csv(). Note that we will execut a extra command\n        \"set datafile separator \",\" to fit the data format of csv.\n        *items: The list of plot command;\n        **kwargs: The options that would be set before the plot command.\n        '''\n    def splot_data(self, data, *items, **kwargs):\n        '''\n        data: The data that need to be plotted. It's either the string of list\n        or the Pnadas Dataframe, if it's Pnadas Dataframe it would be converted\n        to string by data.to_csv(). Note that we will execut a extra command\n        \"set datafile separator \",\" to fit the data format of csv.\n        *items: The list of plot command;\n        **kwargs: The options that would be set before the plot command.\n        '''\n\nWith above functions: constructor, Set()/unset(), plot()/splot(), we can do\nwhat gnuplot do, but it cannot plot python generated data. It's hard to\nimplement the new functions with the existing gnuplot command, so we develop\ntwo new functions: plot_data()/splot_data(). They are much like\nplot()/splot(), the only difference is:\n\n    * plot()/splot() take function(filename) in every plot command.\n    * plot_data()/splot_data() take the dataframe as the first\n      parameter, while remove function(filename) in every plot commmand\n\nfor examples::\n\n    #plot(): 'finance.dat' is in plot command\n    g.plot(\"'finance.dat' using 0:($6/10000) notitle with impulses lt 3\",\n           \"'finance.dat' using 0:($7/10000) notitle with lines lt 1\")\n\n    #plot_data(): the first parameter must be dataframe, every plot\n    #command doesn't take the data.\n    g.plot_data(df,\n            'using 0:($6/10000) notitle with impulses lt 3',\n            'using 0:($7/10000) notitle with lines lt 1')\n\nSee `histograms.2.py`_ and `histograms.2.py`_ for differences.\n\n1.6 multiplot\n------------------\n\nTo plot multiplot, you must set multiplot at first as in gnuplot. Here is examples.\n\n1.7 quick mode\n------------------\n\nFor some easy case, we can combine the following step into one.\n\n    1) Enter gnuplot conext;\n    2) Set plotting style;\n    3) Define some expressions;\n    4) Plotting.\n\nFor examples:\n\n.. _simple2.1.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n\n    gnuplot.plot('[-10:10] sin(x)',\n           'atan(x)',\n           'cos(atan(x))',\n           terminal = 'pngcairo font \"arial,10\" fontscale 1.0 size 600, 400',\n           output = '\"simple.1.png\"',\n           key = 'fixed left top vertical Right noreverse enhanced autotitle box lt black linewidth 1.000 dashtype solid',\n           samples = '50, 50',\n           title = '\"Simple Plots\" font \",20\" textcolor lt -1 norotate',\n           xrange = '[ * : * ] noreverse writeback',\n           x2range = '[ * : * ] noreverse writeback',\n           yrange = '[ * : * ] noreverse writeback',\n           y2range = '[ * : * ] noreverse writeback',\n           zrange = '[ * : * ] noreverse writeback',\n           cbrange = '[ * : * ] noreverse writeback',\n           rrange = '[ * : * ] noreverse writeback',\n           colorbox = 'vertical origin screen 0.9, 0.2 size screen 0.05, 0.6 front noinvert bdefault')\n\n.. _whale2.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n\n    #https://ayapin-film.sakura.ne.jp/Gnuplot/Pm3d/Part1/whale.html\n    gnuplot.splot('\"examples/whale.dat\" w pm3d',\n            term = 'pngcairo size 480,480',\n            out = '\"whale.png\"',\n            style = 'line 100 lw 0.1 lc \"black\"',\n            pm3d = 'depth hidden3d ls 100',\n            cbrange = '[-0.5:0.5]',\n            palette = 'rgb -3,-3,-3',\n            colorbox = None,\n            border = None,\n            key = None,\n            zrange = '[-2:2]',\n            tics = None,\n            view = '60,185,1.5')\n\n.. _histograms2.2.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n\n    df = pd.read_csv('examples/immigration.dat', index_col = 0, sep='\\t', comment='#')\n    gnuplot.plot_data(df,\n            'using 2:xtic(1), for [i=3:22] \"\" using i ',\n            terminal = 'pngcairo transparent enhanced font \"arial,10\" fontscale 1.0 size 600, 400 ',\n            output = '\"histograms.1.png\"',\n            key = 'fixed right top vertical Right noreverse noenhanced autotitle nobox',\n            style = 'data linespoints',\n            datafile = ' missing \"-\"',\n            xtics = 'border in scale 1,0.5 nomirror rotate by -45 autojustify norangelimit',\n            title = '\"US immigration from Europe by decade\"')\n\n.. _surface2.9.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n\n    #py-gnuplot: https://gnuplot.sourceforge.net/demo/surface2.9.gnu\n    gnuplot.splot('cos(u)+.5*cos(u)*cos(v),sin(u)+.5*sin(u)*cos(v),.5*sin(v) with lines',\n            '1+cos(u)+.5*cos(u)*cos(v),.5*sin(v),sin(u)+.5*sin(u)*cos(v) with lines',\n            terminal = 'pngcairo enhanced font \"arial,10\" fontscale 1.0 size 600, 400 ',\n            output = '\"surface2.9.png\"',\n            dummy = 'u, v',\n            key = 'bmargin center horizontal Right noreverse enhanced autotitle nobox',\n            style = ['data lines'],\n            parametric = '',\n            view = '50, 30, 1, 1',\n            isosamples = '50, 20',\n            hidden3d = 'back offset 1 trianglepattern 3 undefined 1 altdiagonal bentover',\n            xyplane = 'relative 0',\n            title = '\"Interlocking Tori\" ',\n            urange = '[ -3.14159 : 3.14159 ] noreverse nowriteback',\n            vrange = '[ -3.14159 : 3.14159 ] noreverse nowriteback')\n\n2. Examples\n=============\n\n2.1 plot/splot function\n-------------------------------\n\n.. _simple.1.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n\n    #py-gnuplot: https://gnuplot.sourceforge.net/demo_6.0/simple.html\n\n    #Ceate a gnuplot context. with \"log = True\" to print the gnuplot execute log.\n    g = gnuplot.Gnuplot(log = True)\n\n    #Set plotting style\n    g.set(terminal = 'pngcairo font \"arial,10\" fontscale 1.0 size 600, 400',\n           output = '\"simple.1.png\"',\n           key = 'fixed left top vertical Right noreverse enhanced autotitle box lt black linewidth 1.000 dashtype solid',\n           samples = '50, 50',\n           title = '\"Simple Plots\" font \",20\" textcolor lt -1 norotate',\n           xrange = '[ * : * ] noreverse writeback',\n           x2range = '[ * : * ] noreverse writeback',\n           yrange = '[ * : * ] noreverse writeback',\n           y2range = '[ * : * ] noreverse writeback',\n           zrange = '[ * : * ] noreverse writeback',\n           cbrange = '[ * : * ] noreverse writeback',\n           rrange = '[ * : * ] noreverse writeback',\n           colorbox = 'vertical origin screen 0.9, 0.2 size screen 0.05, 0.6 front  noinvert bdefault')\n\n    #Expressions and caculations\n    g.cmd(\"NO_ANIMATION = 1\")\n\n    #Plotting\n    g.plot(\"[-10:10] sin(x)\", \"atan(x)\", \"cos(atan(x))\")\n\nThis is the output: \n\n|simple.1.png|\n\n.. _surface.9.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n\n    #py-gnuplot: https://gnuplot.sourceforge.net/demo_6.0/simple.html\n\n    #Ceate a gnuplot context. with \"log = True\" to print the gnuplot execute log.\n    g = gnuplot.Gnuplot(log = True)\n\n    #Set plotting style\n    g.set(terminal = 'pngcairo  transparent enhanced font \"arial,10\" fontscale 1.0 size 600, 400',\n            output = \"'surface2.9.png'\",\n            dummy = 'u, v',\n            key = 'bmargin center horizontal Right noreverse enhanced autotitle nobox',\n            parametric = '',\n            view = '50, 30, 1, 1',\n            isosamples = '50, 20',\n            hidden3d = 'back offset 1 trianglepattern 3 undefined 1 altdiagonal bentover',\n            style = ['data lines'],\n            xyplane = 'relative 0',\n            title = '\"Interlocking Tori\" ',\n            urange = '[ -3.14159 : 3.14159 ] noreverse nowriteback',\n            vrange = '[ -3.14159 : 3.14159 ] noreverse nowriteback',\n            colorbox = 'vertical origin screen 0.9, 0.2 size screen 0.05, 0.6 front  noinvert bdefault')\n\n    #Expressions and caculations\n    g.cmd(\"NO_ANIMATION = 1\")\n\n    #Plotting\n    g.splot(\"cos(u)+.5*cos(u)*cos(v)\",\n            \"sin(u)+.5*sin(u)*cos(v)\",\n            \".5*sin(v) with lines\",\n            \"1+cos(u)+.5*cos(u)*cos(v)\",\n            \".5*sin(v),sin(u)+.5*sin(u)*cos(v) with lines\",\n            )\n\nThis is the output: \n\n|surface2.9.png|\n\n2.2 plot/splot file\n-------------------------------\n\n.. _histograms.2.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n\n    #Histograms demo example comes from\n    #https://gnuplot.sourceforge.net/demo_6.0/histograms.2.gnu\n\n    #1) Ceate a gnuplot context\n    g = gnuplot.Gnuplot(log = True)\n\n    #2) Set plotting style\n    g.set(terminal = 'pngcairo  transparent enhanced font \"arial,10\" fontscale 1.0 size 600, 400',\n            output = \"'histograms.2.png'\",\n            boxwidth = '0.9 absolute',\n            style = ['fill   solid 1.00 border lt -1',\n                'histogram clustered gap 1 title textcolor lt -1',\n                'data histograms' ],\n            key = 'fixed right top vertical Right noreverse noenhanced autotitle nobox',\n            datafile = \"missing '-'\",\n            xtics = [\"border in scale 0,0 nomirror rotate by -45  autojustify\",\n                \"norangelimit \",\n                \" ()\"],\n            title = '\"US immigration from Northern Europe\\\\nPlot selected data columns as histogram of clustered boxes\"',\n            xrange = '[ * : * ] noreverse writeback',\n            x2range = '[ * : * ] noreverse writeback',\n            yrange  = '[ 0.00000 : 300000. ] noreverse writeback',\n            y2range = '[ * : * ] noreverse writeback',\n            zrange = '[ * : * ] noreverse writeback',\n            cbrange = '[ * : * ] noreverse writeback',\n            rrange = '[ * : * ] noreverse writeback',\n            colorbox = 'vertical origin screen 0.9, 0.2 size screen 0.05, 0.6 front  noinvert bdefault')\n\n    #3) Expressions and caculations\n    g.cmd(\"NO_ANIMATION = 1\")\n\n    #4) Plotting\n    g.plot(\"'examples/immigration.dat' using 6:xtic(1) ti col\",\n            \"'' u 12 ti col\",\n            \"'' u 13 ti col\",\n            \"'' u 14 ti col\")\n\nThis is the output: \n\n|histograms.2.png|\n\nAnother example is to splot a pm3d image:\n\n.. _whale.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n\n    #Whale example comes from\n    #https://ayapin-film.sakura.ne.jp/Gnuplot/Pm3d/Part1/whale.html\n\n    #Ceate a gnuplot context\n    g = gnuplot.Gnuplot(log = True)\n\n    #Set plotting style\n    g.set(term = 'pngcairo size 480,480',\n            output = '\"whale.png\"',\n            style = 'line 100 lw 0.1 lc \"black\"',\n            pm3d = 'depth hidden3d ls 100',\n            cbrange = '[-0.5:0.5]',\n            palette = 'rgb -3,-3,-3',\n            colorbox = None,\n            border   = None,\n            key = None,\n            zrange = '[-2:2]',\n            tics  = None,\n            view = '60,185,1.5')\n\n    #No Expressions\n\n    #Plotting\n    g.splot('\"examples/whale.dat\" w pm3d')\n\nThe generated image is as below:\n\n|whale.png|\n\n2.3 plot/splot python generated data\n----------------------------------------------\n\n.. _histograms3.2.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n\n    #Histograms demo example comes from\n    #https://gnuplot.sourceforge.net/demo_6.0/histograms.2.gnu\n\n    #1) Ceate a gnuplot context\n    g = gnuplot.Gnuplot(log = True)\n\n    #2) Set plotting style\n    g.set(terminal = 'pngcairo  transparent enhanced font \"arial,10\" fontscale 1.0 size 600, 400',\n            output = \"'histograms.2.png'\",\n            boxwidth = '0.9 absolute',\n            style = ['fill   solid 1.00 border lt -1',\n                'histogram clustered gap 1 title textcolor lt -1',\n                'data histograms' ],\n            key = 'fixed right top vertical Right noreverse noenhanced autotitle nobox',\n            datafile = \"missing '-'\",\n            xtics = [\"border in scale 0,0 nomirror rotate by -45  autojustify\",\n                \"norangelimit \",\n                \" ()\"],\n            title = '\"US immigration from Northern Europe\\\\nPlot selected data columns as histogram of clustered boxes\"',\n            xrange = '[ * : * ] noreverse writeback',\n            x2range = '[ * : * ] noreverse writeback',\n            yrange  = '[ 0.00000 : 300000. ] noreverse writeback',\n            y2range = '[ * : * ] noreverse writeback',\n            zrange = '[ * : * ] noreverse writeback',\n            cbrange = '[ * : * ] noreverse writeback',\n            rrange = '[ * : * ] noreverse writeback',\n            colorbox = 'vertical origin screen 0.9, 0.2 size screen 0.05, 0.6 front  noinvert bdefault')\n\n    #3) Expressions and caculations\n    g.cmd(\"NO_ANIMATION = 1\")\n    #The original example is plotting file, it's easy. To demonstrate plotting\n    #data generated in python, we transform the data into df for demonstration.\n    df = pd.read_csv('examples/immigration.dat', index_col = 0, sep='\\t', comment='#')\n\n    #4) Plotting\n    g.plot_data(df,\n            'using 6:xtic(1) ti col',\n            'u 12 ti col',\n            'u 13 ti col',\n            'u 14 ti col')\n\nThe generated image is as below:\n\n|histograms.2.png|\n\n2.4 multiplot examples\n------------------------------\n\n.. _finance.13.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n\n    #Transparent demo example comes from\n    #https://gnuplot.sourceforge.net/demo_6.0/finance.html\n\n    #Ceate a gnuplot context\n    g = gnuplot.Gnuplot(log = True)\n\n    #Set plotting style\n    g.set(output = \"'finance.13.png'\",\n            term = 'pngcairo  transparent enhanced font \"arial,8\" fontscale 1.0 size 660, 320',\n            label = ['1 \"Acme Widgets\" at graph 0.5, graph 0.9 center front',\n                '2 \"Courtesy of Bollinger Capital\" at graph 0.01, 0.07',\n                '3 \"  www.BollingerBands.com\" at graph 0.01, 0.03'],\n            logscale = 'y',\n            yrange = '[75:105]',\n            ytics = '(105, 100, 95, 90, 85, 80)',\n            xrange = '[50:253]',\n            grid = '',\n            lmargin = '9',\n            rmargin = '2',\n            format = 'x \"\"',\n            xtics = '(66, 87, 109, 130, 151, 174, 193, 215, 235)',\n            multiplot = True)\n\n    #3) Expressions and caculations\n\n    #4) Plotting: Since multiplot = True, we plot two subplot\n    g.plot(\"'finance.dat' using 0:2:3:4:5 notitle with candlesticks lt 8\",\n            \"'finance.dat' using 0:9 notitle with lines lt 3\",\n            \"'finance.dat' using 0:10 notitle with lines lt 1\",\n            \"'finance.dat' using 0:11 notitle with lines lt 2\",\n            \"'finance.dat' using 0:8 axes x1y2 notitle with lines lt 4\",\n            title = '\"Change to candlesticks\"',\n            size = ' 1, 0.7',\n            origin = '0, 0.3',\n            bmargin = '0',\n            ylabel = '\"price\" offset 1')\n    g.plot(\"'finance.dat' using 0:($6/10000) notitle with impulses lt 3\",\n            \"'finance.dat' using 0:($7/10000) notitle with lines lt 1\",\n            bmargin = '',\n            format = ['x', 'y \"%1.0f\"'],\n            size = '1.0, 0.3',\n            origin = '0.0, 0.0',\n            tmargin = '0',\n            nologscale = 'y',\n            autoscale = 'y',\n            ytics = '500',\n            xtics = '(\"6/03\" 66, \"7/03\" 87, \"8/03\" 109, \"9/03\" 130, \"10/03\" 151, \"11/03\" 174, \"12/03\" 193, \"1/04\" 215, \"2/04\" 235)',\n            ylabel = '\"volume (0000)\" offset 1')\n\n.. _finance3.13.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n\n    #Transparent demo example comes from\n    #https://gnuplot.sourceforge.net/demo_6.0/finance.html\n\n    #Ceate a gnuplot context\n    g = gnuplot.Gnuplot(log = True)\n\n    #Set plotting style\n    g.set(output = \"'finance.13.png'\",\n            term = 'pngcairo  transparent enhanced font \"arial,8\" fontscale 1.0 size 660, 320',\n            label = ['1 \"Acme Widgets\" at graph 0.5, graph 0.9 center front',\n                '2 \"Courtesy of Bollinger Capital\" at graph 0.01, 0.07',\n                '3 \"  www.BollingerBands.com\" at graph 0.01, 0.03'],\n            logscale = 'y',\n            yrange = '[75:105]',\n            ytics = '(105, 100, 95, 90, 85, 80)',\n            xrange = '[50:253]',\n            grid = '',\n            lmargin = '9',\n            rmargin = '2',\n            format = 'x \"\"',\n            xtics = '(66, 87, 109, 130, 151, 174, 193, 215, 235)',\n            multiplot = True)\n\n    #3) Expressions and caculations\n    #A demostration to generate pandas data frame data in python.\n    df = pd.read_csv('examples/finance.dat',\n            sep='\\t',\n            index_col = 0,\n            parse_dates = True,\n            names = ['date', 'open','high','low','close', 'volume','volume_m50',\n                'intensity','close_ma20','upper','lower '])\n\n    #4) Plotting: Since multiplot = True, we plot two subplot\n    g.plot_data(df,\n            'using 0:2:3:4:5 notitle with candlesticks lt 8',\n            'using 0:9 notitle with lines lt 3',\n            'using 0:10 notitle with lines lt 1',\n            'using 0:11 notitle with lines lt 2',\n            'using 0:8 axes x1y2 notitle with lines lt 4',\n            title = '\"Change to candlesticks\"',\n            size = ' 1, 0.7',\n            origin = '0, 0.3',\n            bmargin = '0',\n            ylabel = '\"price\" offset 1')\n    g.plot_data(df,\n            'using 0:($6/10000) notitle with impulses lt 3',\n            'using 0:($7/10000) notitle with lines lt 1',\n            bmargin = '',\n            format = ['x', 'y \"%1.0f\"'],\n            size = '1.0, 0.3',\n            origin = '0.0, 0.0',\n            tmargin = '0',\n            nologscale = 'y',\n            autoscale = 'y',\n            ytics = '500',\n            xtics = '(\"6/03\" 66, \"7/03\" 87, \"8/03\" 109, \"9/03\" 130, \"10/03\" 151, \"11/03\" 174, \"12/03\" 193, \"1/04\" 215, \"2/04\" 235)',\n            ylabel = '\"volume (0000)\" offset 1')\n\nBoth script generate the same output image:\n\n|finance.13.png|\n\n2.5 Examples port from matplotlib\n-----------------------------------\n\nJust for fun, I translate some examples in matplotlib to py-gnuplot:\n\n2.5.1 Stacked bar chart\n+++++++++++++++++++++++\n\n.. _sphx_glr_bar_stacked_001.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n\n    # data is from https://matplotlib.org/gallery/lines_bars_and_markers/bar_stacked.html#sphx-glr-gallery-lines-bars-and-markers-bar-stacked-py\n    #https://matplotlib.org/_downloads/2ac62a2edbb00a99e8a853b17387ef14/bar_stacked.py\n    labels = ['G1', 'G2', 'G3', 'G4', 'G5']\n    men_means = [20, 35, 30, 35, 27]\n    women_means = [25, 32, 34, 20, 25]\n    men_std = [2, 3, 4, 1, 2]\n    women_std = [3, 5, 2, 3, 3]\n    width = 0.35       # the width of the bars: can also be len(x) sequence\n\n    # Plot programme:\n    df = pd.DataFrame({'men_means': men_means,\n        'women_means': women_means,\n        'men_std': men_std,\n        'women_std': women_std}, index = labels)\n    #print(df)\n    gnuplot.plot_data(df,\n            'using :($2 + $3):5:xtic(1) with boxerror title \"women\" lc \"dark-orange\"',\n            'using :2:4 with boxerror title \"men\" lc \"royalblue\"',\n            style = ['data boxplot', 'fill solid 0.5 border -1'],\n            boxwidth = '%s' %(width),\n            xrange = '[0.5:5.5]',\n            ylabel = '\"Scores\"',\n            title = '\"Scores by group and gender\"',\n            output = '\"sphx_glr_bar_stacked_001.png\"',\n            terminal = 'pngcairo size 640, 480')\n\nThis is the output:\n\n|sphx_glr_bar_stacked_001.png|\n\n2.5.2 Grouped bar chart with labels\n+++++++++++++++++++++++++++++++++++\n\n.. _sphx_glr_barchart_001.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n\n    # data is from https://matplotlib.org/gallery/lines_bars_and_markers/barchart.html#sphx-glr-gallery-lines-bars-and-markers-barchart-py\n    labels = ['G1', 'G2', 'G3', 'G4', 'G5']\n    men_means = [20, 34, 30, 35, 27]\n    women_means = [25, 32, 34, 20, 25]\n    width = 0.35  # the width of the bars\n\n    # Plot programme:\n    df = pd.DataFrame({'men': men_means, 'women': women_means},\n            index = labels)\n    df.index.name = 'label'\n    #print(df)\n    gnuplot.plot_data(df,\n            'using 2:xticlabels(1) title columnheader(2) lc \"web-blue\"',\n            'using 3:xticlabels(1) title columnheader(3) lc \"orange\"',\n            'using ($0-0.2):($2+1):2 with labels notitle column',\n            'using ($0+0.2):($3+1):3 with labels notitle column',\n            title = '\"Scores by group and gender\"',\n            xrange = '[-0.5:4.5]',\n            yrange = '[0:38]',\n            ylabel = '\"Scores\"',\n            style = ['data histogram',\n                     'histogram cluster gap 1',\n                     'fill solid border -1',\n                     'textbox transparent'],\n            output = '\"sphx_glr_barchart_001.png\"',\n            terminal = 'pngcairo size 640, 480')\n\nThis is the output:\n\n|sphx_glr_barchart_001.png|\n\n2.5.3 Multiplot Axes Demo\n+++++++++++++++++++++++++\n\n.. _sphx_glr_axes_demo_001.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n    import numpy as np\n\n    #https://matplotlib.org/gallery/subplots_axes_and_figures/axes_demo.html#sphx-glr-gallery-subplots-axes-and-figures-axes-demo-py\n    #http://gnuplot.sourceforge.net/demo_5.2/bins.html\n\n    # 1) create some data to use for the plot\n    np.random.seed(19680801) # Fixing random state for reproducibility\n    dt = 0.001\n    t = np.arange(0.0, 10.0, dt)\n    r = np.exp(-t / 0.05)  # impulse response\n    x = np.random.randn(len(t))\n    s = np.convolve(x, r)[:len(x)] * dt  # colored noise\n    df = pd.DataFrame({'r': r, 'x': x, 's': s}, index = t)\n    df.index.name = 't'\n\n    g = gnuplot.Gnuplot(log = True,\n            output = '\"sphx_glr_axes_demo_001.png\"',\n            term = 'pngcairo font \"arial,10\" fontscale 1.0 size 640, 480',\n            key = '',\n            multiplot = True)\n\n    # 2) Plot the data\n    g.plot_data(df.iloc[:1000],\n            'using 1:4 with line lw 2 lc \"web-blue\"',\n            title = '\"Gaussian colored noise\"',\n            xlabel = '\"time (s)\"',\n            ylabel = '\"current (nA)\"',\n            xrange = '[0:1]',\n            yrange = '[-0.015:0.03]',\n            key = None,\n            size = ' 1, 1',\n            origin = '0, 0')\n    g.plot_data(df,\n            'using 4 bins=400 with boxes title \"20 bins\" lw 2 lc \"web-blue\"',\n            title = '\"Probability\"',\n            xlabel = None,\n            ylabel = None,\n            tics = None,\n            xrange = None,\n            yrange = None,\n            origin = '0.65, 0.56',\n            size = '0.24, 0.32',\n            object = 'rectangle from graph 0,0 to graph 1,1 behind fc \"black\" fillstyle solid 1.0')\n    g.plot_data(df,\n            'using 1:2 with line lw 2 lc \"web-blue\"',\n            title = '\"Impulse response\"',\n            xrange = '[0:0.2]',\n            origin = '0.15, 0.56',\n            size = '0.24, 0.32')\n\nThis is the output:\n\n|sphx_glr_axes_demo_001.png|\n\n2.5.4 control view and zoom \n++++++++++++++++++++++++++++\n\n.. _sphx_glr_axes_margins_001.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n\n    #https://matplotlib.org/gallery/subplots_axes_and_figures/axes_margins.html#sphx-glr-gallery-subplots-axes-and-figures-axes-margins-py\n    g = gnuplot.Gnuplot(log = True,\n            output = '\"sphx_glr_axes_margins_001.png\"',\n            term = 'pngcairo font \"arial,10\" fontscale 1.0 size 640,480',\n            multiplot = True)\n\n    g.cmd('f(x) = exp(-x) * cos(2*pi*x)')\n    g.plot('sample [x=0:3] \"+\" using (x):(f(x)) with lines',\n            title = '\"Zoomed out\"',\n            key = None,\n            xrange = '[-6: 9]',\n            yrange = '[-4: 4]',\n            xtics = '-5, 5, 5',\n            ytics = '-2, 2, 4',\n            origin = '0, 0.5',\n            size = '0.5, 0.5')\n    g.plot('f(x)',\n            title = '\"Zoomed in\"',\n            key = None,\n            xrange = '[0: 3]',\n            yrange = '[-0.2: 0.5]',\n            xtics = '0, 1, 2',\n            ytics = '-0.2, 0.2, 0.4',\n            origin = '0.5, 0.5',\n            size = '0.5, 0.5')\n    g.plot('f(x)',\n            title = None,\n            key = None,\n            xrange = '[0: 3]',\n            yrange = '[-0.7: 1]',\n            xtics = '0, 0.5, 3',\n            ytics = '-0.5, 0.5, 1',\n            origin = '0, 0',\n            size = '1, 0.5')\n\nThis is the output:\n\n|sphx_glr_axes_margins_001.png|\n\n2.5.5 Rendering math equation using TeX\n+++++++++++++++++++++++++++++++++++++++\n\nWe can embed the TeX math equation into the gnuplot generated image by setting\nthe epslatex terminal, it would be rendered as a .tex file, you can import it\ndirectly or you can convert it to .pdf file and then .png file if needed. this\nis the example:\n\n.. _sphx_glr_tex_demo_001.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n\n    # https://matplotlib.org/gallery/text_labels_and_annotations/tex_demo.html#sphx-glr-gallery-text-labels-and-annotations-tex-demo-py\n    # http://wap.sciencenet.cn/blog-373392-500657.html\n    # https://www.thinbug.com/q/17593917\n    g = gnuplot.Gnuplot(log = True,\n            output = '\"sphx_glr_tex_demo_001.tex\"',\n            term = 'epslatex standalone lw 2 color colortext')\n\n    # NOTE: In the following example, we need to escape the \"\\\", that means we\n    # should use '\\\\' or \"\\\\\\\\\" for \\\n    g.plot('cos(4*pi*x) + 2',\n            xlabel = \"'\\\\textbf{time (s)}'\",\n            ylabel = \"'\\\\textit{Velocity (\\N{DEGREE SIGN}/sec)}'\",\n            title = \"'\\\\TeX\\\\ is Number $\\\\displaystyle\\\\sum_{n=1}^\\\\infty\\\\frac{-e^{i\\\\pi}}{2^n}$!' tc 'red'\",\n            key = None,\n            xrange = '[0: 1]')\n\nThis is the output:\n\n|sphx_glr_tex_demo_001.png|\n\nI list the script output since it's with the log=True::\n\n    [py-gnuplot 14:56:13] set output \"sphx_glr_tex_demo_001.tex\"\n    [py-gnuplot 14:56:13] set term epslatex standalone lw 2 color colortext\n    [py-gnuplot 14:56:13] set xlabel '\\textbf{time (s)}'\n    [py-gnuplot 14:56:13] set ylabel '\\textit{Velocity (\u00b0/sec)}'\n    [py-gnuplot 14:56:13] set title '\\TeX\\ is Number $\\displaystyle\\sum_{n=1}^\\infty\\frac{-e^{i\\pi}}{2^n}$!' tc 'red'\n    [py-gnuplot 14:56:13] unset key\n    [py-gnuplot 14:56:13] set xrange [0: 1]\n    [py-gnuplot 14:56:13] plot cos(4*pi*x) + 2\n\n2.5.6 Basic pie chart\n+++++++++++++++++++++\n\n.. _sphx_glr_pie_features_0011.py:\n.. code-block:: python\n\n    #!/usr/bin/env python3\n    #coding=utf8\n    from pygnuplot import gnuplot\n    import pandas as pd\n    import math\n\n    #http://www.phyast.pitt.edu/~zov1/gnuplot/html/pie.html\n    #https://matplotlib.org/gallery/pie_and_polar_charts/pie_features.html#sphx-glr-gallery-pie-and-polar-charts-pie-features-py\n    # Pie chart, where the slices will be ordered and plotted counter-clockwise:\n    labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'\n    sizes = [15, 30, 45, 10]\n    explode = (0, 0.1, 0, 0)  # only \"explode\" the 2nd slice (i.e. 'Hogs')\n    startangle = math.pi/2\n\n    # Prepare the data: caculate the percentage\n    df = pd.DataFrame({'labels': labels, 'sizes': sizes, 'explode': explode})\n    df.index.name = 'index'\n    df['percentage'] = df['sizes'] / df['sizes'].sum()\n    df['end'] = df['percentage'].cumsum()*2*math.pi + startangle\n    #df['start'] = df['end'].shift(axis=0, fill_value = 0)\n    df['start'] = df['end'].shift(axis=0)\n    df = df.fillna(startangle)\n    #print(df)\n\n    pie_shade = []\n    pie_graph = []\n\n    shade_offset = 0.03\n    g = gnuplot.Gnuplot(log = True,\n            output = '\"sphx_glr_pie_features_0011.png\"',\n            term = 'pngcairo size 640, 480',\n            key = None,\n            parametric = \"\",\n            border = \"\",\n            tics = \"\",\n            multiplot = True)\n\n    for k, v in df.iterrows():\n        #print(k,v)\n        cos = math.cos((v['start']+v['end'])/2)\n        sin = math.sin((v['start']+v['end'])/2)\n\n        # If we'd like explode the piece, ad the dx/dy to move the origi point.\n        dx = v['explode'] * cos\n        dy = v['explode'] * sin\n\n        # make the shade for each piece\n        g.plot('cos(t)+%f, sin(t)+%f with filledcurves xy=%f,%f lc \"grey80\"'\n                %(dx-shade_offset, dy-shade_offset, dx-shade_offset, dy-shade_offset),\n                trange = '[%f:%f]' %(v['start'], v['end']),\n                xrange = '[-1.5:1.5]',\n                yrange = '[-1.5:1.5]')\n\n        # make the pie and label\n        g.plot('cos(t)+%f, sin(t)+%f with filledcurve xy=%f,%f  lt %d'\n                %(dx, dy, dx, dy, k+3),\n                trange = '[%f:%f]' %(v['start'], v['end']),\n                xrange = '[-1.5:1.5]',\n                yrange = '[-1.5:1.5]',\n                label = ['1 \"%s\" at %f, %f center front' %(v['labels'], 1.2*cos+dx, 1.2*sin+dy), '2 \"%.1f%%\" at %f, %f center front' %(v['percentage']*100, 0.6*cos, 0.6*sin)])\n\nThis is the output:\n\n|sphx_glr_pie_features_0011.png|\n\n3. Q/A\n=======\n\n4. CHANGLOG\n=============\n\n1.0 Initial upload;\n\n1.0.3 Now Gnuplot().plot()/splot() supplot set options as parameters.\n\n1.0.7 The pyplot.plot() now can accept both string and pandas.Dataframe as the\nfirst parameter, Further more we need pandas installed at first.\n\n1.0.11 Fix the bug: gnuplot.multiplot() doesn't work.\n\n1.0.15 1) Add an example of comparing the object-oriented interface call and\nglobal class-less function call in multiplot() in multiplot() in\nmultiplot() in multiplot(). 2) remove some duplicate setting line.\n\n1.0.19 Add a log options to enable the log when run the script.\n\n1.1 Upgrade to 1.1: 1) Submodule pyplot is depreciated. 2) To plot python generated\ndata we use gnuplot.plot_data() and gnuplot.splot_data().\n\n\n1.1.2 Enhancement: If it's multiplot mode, automatically call the following\nGnuplot to unset the label:\n\n    g.unset('for [i=1:200] label i')\n\n1.1.3 Enhancement: When plotting the python generated data, we set the\nseperator to \",\" for easy using it in csv file.\n\n1.1.5 Bug fix: on some case it exit exceptionally.\n\n1.1.8 Remove some Chinese comments to remove the \"UnicodeDecodeError\" for some users.\n\n1.1.9 1) Run and update the examples in gnuplot6.0.0. 2) If you'd like enable multiplot, you shuld use  multimplot = True to replace multimplot = \"\".\n\n1.1.13 Document update.\n\n\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "py-gnuplot is a python plot tools based on gnuplot.",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "http://www.gnuplot.info"
    },
    "split_keywords": [
        "gnuplot",
        "pandas"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "005803f817c95458cc51c3340c025bda3417e7e645576f4738496d8b6d3bd680",
                "md5": "73c9135376dafd26ab3d062aa672606d",
                "sha256": "7a06ec40749c56a6c42be3c15909b229f4fb3893cef6afa448cf4fbffbf815a6"
            },
            "downloads": -1,
            "filename": "py-gnuplot-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "73c9135376dafd26ab3d062aa672606d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 32191,
            "upload_time": "2024-02-06T15:46:30",
            "upload_time_iso_8601": "2024-02-06T15:46:30.615369Z",
            "url": "https://files.pythonhosted.org/packages/00/58/03f817c95458cc51c3340c025bda3417e7e645576f4738496d8b6d3bd680/py-gnuplot-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-06 15:46:30",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "py-gnuplot"
}
        
Elapsed time: 0.18452s