GithubHelp home page GithubHelp logo

acorbe / autogpy Goto Github PK

View Code? Open in Web Editor NEW
10.0 4.0 0.0 3.81 MB

Gnuplot scripts and figures auto-generated in Python. Production-ready, Latex and Tikz rendering.

Home Page: https://acorbe.github.io/autogpy/

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
python3 plotting-in-python gnuplot numpy gnuplot-graphs gnuplot-interface jupyter tikz

autogpy's Introduction

autogpy - AutoGnuplot.py

Automatic generation of gnuplot figures/scripts/data from python.

Author: Alessandro Corbetta, 2019-2020
Documentation: https://acorbe.github.io/autogpy/
Examples Link
Github Link

PyPI build status DownloadsPyPI - Downloads

Which problem does it solve? Open In Colab

autogpy eliminates annoying duplications of code and data when employing python for data analysis and gnuplot for figures. Providing a gnuplot-like or a matplotlib-like syntax, autogpy automatically generates gnuplot scripts and dumps suitably the data.

Autogpy-Demo

Links: [Source] [Output]

Main features

  • [Reference] [Example 1 2] anything that be obtained by the gnuplot command plot can be produced
  • output figures are shipped in a folder which includes scripts, data and makefile
  • any gnuplot state modification can be achieved
  • terminals epslatex, tikz/pgfplot and jpg
  • multiplots
  • plt.hist-like gnuplot histogram figures generator
  • jupyter notebook figure preview
  • jupyter notebook gnuplot script inspection
  • easy scp-based synchronization between a machine in which the figures are generated (e.g. from even larger datasets) and the "paper writing" machine.

Requirements

  • Linux/MacOs (could work on Windows, yet it has not been adjusted for)
  • Python 3
  • Working latex distribution
  • Gnuplot, optionally with tikz terminal (tikz terminal requires a working installation of luatex)
  • pdftoppm (via poppler-utils) or imagemagick to convert the output pdf figures in png format for jupyter notebook preview
  • Note: in case pdftoppm is unavailable, imagemagick offline conversions pdf to png must be enabled (sudo sed -i '/PDF/s/none/read|write/' /etc/ImageMagick-6/policy.xml) [Reference]

Getting autogpy

Via pip

pip install autogpy

On Google Colab

!apt install gnuplot texlive poppler-utils ghostscript texlive-latex-extra
!pip install autogpy

From source

git clone [email protected]:acorbe/autogpy.git
pip install autogpy/

In a nutshell

Please see also the examples and the documentation.

import autogpy
import numpy as np

xx = np.linspace(0,6,100)
yy = np.sin(xx)
zz = np.cos(xx)

with autogpy.AutogpyFigure("test_figure") as figure: 

	# gnuplot-like syntax
	figure.plot(r'with lines t "sin"',xx,yy)
	
	# matplotlib-like syntax
	figure.plot(xx,zz,u='1:2',w='lines',label='cos')

generates the following figure (also appearing in jupyter)

example figure

Most importantly, the following source and data are created in the folder test_figure

$ ls test_figure

.gitignore
Makefile
sync_me.sh
fig__0__.dat
fig__1__.dat
fig__.core.gnu
fig__.jpg.gnu
fig__.pdflatex_compile.sh
fig__.pdflatex.gnu
fig__.tikz_compile.sh
fig__.tikz.gnu

With make one can obtain jpg, epslatex, and tikz/pgfplot versions of the figure. Notice that the input data has been formatted automatically and dumped in the .dat files.

Inspecting the fig__.pdflatex.gnu, responsible of the epslatex version of the figure, one gets:

set terminal epslatex size 9.9cm,8.cm color colortext standalone      'phv,12 '  linewidth 2
set output 'fig.latex.nice/plot_out.tex'

p "fig__0__.dat" with lines t "sin",\
"fig__1__.dat" u 1:2 with lines t "cos" 

KWONW ISSUES

  • Certain features require imagemagick and a working gnuplot-tikz.lua. Some versions of these might have bugs. Call figure.display_fixes() to show known fixes.

autogpy's People

Contributors

acorbe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

autogpy's Issues

Multiple symbols in superscript

@acorbe

A superscript with a single variable (x^a) works. However, multiple variables (x^{abc}) in superscripts gives an error when using autognuplot in python, see screenshot.

Adapting the fig__.core.gnu file and hitting make from the command line does indeed produce the desired result. The error is hence python/autognuplot related.

The code:
p1.p_generic(r'u 1 : 2 w points t "Synthetic data $\sim N^{-0.23}$" lt 1 lw 2 ', nb_samples, xbar)

Schermafbeelding 2019-07-03 om 15 48 32

Histogram reweight expects normalized hist, otherwise datatype conversion fails

Error:

import autogpy

del_vs_avg_f = autogpy.AutoGnuplotFigure('delay_vs_avg_speed','fig',tikz_enabled=True)

for key, v in grp_stats_loc_data.groupby(grp_stats_loc_data_bins).delay_uwr:
    del_vs_avg_f.hist_generic( v
                               , 't "v" w l'                               
                               , hist_kw = { 'bins' : 250 }                               
    )

del_vs_avg_f.generate_gnuplot_file()
del_vs_avg_f.jupyter_show()
    
Truncated Traceback (Use C-c C-$ to view full TB):
~/workspace/autogpy/autogpy/autognuplot.py in hist_generic(self, x, gnuplot_command_no_u, hist_kw, gnuplot_command_using, normalization, kde, kde_kw, reweight, **kw)
    407             v_ = kde_vals
    408 
--> 409         v_ *= reweight(edges_mid)
    410 
    411         N_coeff = self.__hist_normalization_function(v_,normalization)

TypeError: Cannot cast ufunc multiply output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.