Code Monkey home page Code Monkey logo

vtikz's Introduction

vTikz

A simple way to generate standalone tikz figures in V, worthy of scientific publications.

Installation

To install vtikz, run the following command in your shell/terminal:

v install --git https://github.com/thesombady/vtikz

This requires the V package manager to be installed, and for compiling the generated .tex file, a LaTeX distribution is required with tikz and pgfplots, for example: texlive, miktex, etc. One change the latex compiler by changing the compiler field in the preference structure.

Why vTikz?

Why would you use vTikz over other plotting libraries? Some libraries are complicated to use, and some does not generate standalone figures. In vTikz, the figures are standalone, and can be used in any LaTex document. Moreover, vTikz is simple to use, and the default settings are set to generate figures that are on par with scientific publications. The user can easily customize major aspects of the figures, such as:

  1. Axis labels
  2. Title
  3. Legend position
  4. Axis alignment
  5. Line style
  6. Marker style
  7. Fillers in 3d plots
  8. Color maps
  9. Ticks labels, and much more.

vTikz is designed to be simple to use, and generate standalone tikz figures, with the option to keep the .tex file after compilation (with readable tex code).

Squared function

Usage

For examples, see the Examples directory.

The following are the types of plots that can be created in vTikz:

  1. Scatter Plots
    • Scatter plots are a series of data, where each data point is represented by a marker. These markers can be customized to different shapes.
    • The markers are connected by lines by default, but this can be changed.
  2. Function plots (2d)
    • Functions are represented as a string, e.g. "x^2 + 2x + 1", which would be a quadratic function in "x".
    • The function can be customized to have different colors and line styles (dashed, thin, thick, etc.).
  3. Function plots (3d)
    • Functions are represented as a string in the form 'z = f(x, y)', where 'z' is the dependent variable and 'x' and 'y' are the independent variables, e.g. "x^2 + y^2".
    • This mode supports mesh, surface and line plots. Each of these can be customized with the color map, and in the specific case of surface plot, also the fill-color (by default white).
  4. Scatter plots 3d
    • In this mode, the assumption of an equispaced grid is made, and the data is represented as a matrix of z-values. [][]f32.
    • This mode supports mesh and surface plots. Each of these can be customized with the color map, and in the specific case of surface plot, also the fill-color (by default white).
  5. Bar plots (Not yet implemented)
    • Bar plots are a series of data, where each data point is represented by a bar. These bars can be customized to different colors and patterns.
  6. Logarithmic plots
    • The x and y-axis can be set to logarithmic scales.

Structure of the package

To generate a new plot, one has to create an instance of Tikz, which is the core of the generator. The Tikz struct has the following fields:

struct Tikz {
    pref Pref // The preferences for the plot
    axis Axis // The axis of the plot
    plots []Plot // The plots to be added to the plot
}

mut tikz := Tikz.new(
    xlabel,
    ylabel,
    title
)

The preferences, pref allows for some choosing compiler: texlive, pdflatex. It also allows for keeping the .tex file after creating the plot.

This package is made to be simple and easy to use, but still generate tikz figures that are on par with the quality of scientific publications.

Examples

For more examples, see the Examples directory.

Scatter Plot

import vtikz

x := [f32(1), 2, 3, 4, 5]
y := [f32(1), 4, 10, 15, 26] // Assume this to be experimental data of x^2

mut tikz := Tikz.new(
    'x', // xlabel
    'y', // ylabel
    'Our first plot'
)

tikz.add_scatter(x, y, 'blue', 'Experimental data') // We add the scatter data

tikz.add_function(
    "x^2", // The function
    'red', // The color
    'Fitted data', // The line style
    [f32(3), 5]! // The range of x (Not in agreement with the data, but for the sake of the example)
)

// When adding the second plot the xlimits are set to the range of the enitre data set, i.e. [1, 5]!, and vtikz will automatically show the legends when adding the second plot

// We can change the compiler by changing the preference structure
tikz.set_compiler(vtikz.Compiler.texlive)
// The default is .pdflatex and we have .@none

// If we dont want the .tex file to be compiled, we can set the field keep_tex to true
tikz.set_keep_tex(true)

// If we dont want the pdf to automatically open, we do the following:
tikz.set_open_pdf(false)

// Note, all the auxiliary files are deleted.

// If you want to change the legend position, you can do the following:

tikz.set_legend_pos(vtikz.Legend_pos.north_east) // This is the same as the above

// Iff you want to change the alignment of the graph, you can do the following:

tikz.set_axis_line(.center)

// If the standard tick labels are not what you want, you can change them by doing the following:

tikz.set_xtick([f32(1), 2.5, 5])//All values must be f32.

tikz.plot('scatter_plot.tex') // Save the plot to a .tex file

vtikz's People

Contributors

thesombady avatar

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.