Inkscape extension to plot a set of points, given their coordinates (x,y)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs/images
LICENSE
README.md
cartesianPlotData2D.inx
cartesianPlotData2D.py

README.md

cartesianPlotData2D

Inkscape extension to plot a set of points, given their coordinates (x,y)

main features

The main features are

  • linear and log10 scales
  • optional grid lines in X and Y directions
  • adjustable tick mark intervals and sizes
  • LaTeX support
  • can read data from text file

This extension is specially useful when used in conjunction with other mathematical tools, e.g. Octave, Matlab, R, etc. to plot data generated by these in Inkscape.

You can either provide the data in two strings 'X values' and 'Y values' (numbers must be separated by spaces) or by providing the path of a text file containing a table of X (column 1) and Y data (column 2,3,...). You can inform the preferred field separator.

In case of data provided via text file, multiple plots can be generated at once by providing Y data of each plot in different columns. The same 'X values' is assumed.

Installation and requirements

This extension was partially developed in Inkscape 0.48 and partially in 0.91 in Linux (Kubuntu 12.04 and 14.04). It should work on both versions of Inkscape. Also, they should work in different OSs too as long as all requirements are installed.

This extension requires another extension to run, inkscapeMadeEasy https://github.com/fsmMLK/inkscapeMadeEasy, which contains several backstage methods and classes.

In order to use cartesianPlotData2D extension, you must also download inkscapeMadeEasy files and put them inside Inkscape's extension directory. Please refer to inkscapeMadeEasy installation instructions. In the end you must have the following files and directories in your Inkscape extension directory.

inkscape/extensions/
            |-- inkscapeMadeEasy_Base.py
            |-- inkscapeMadeEasy_Draw.py
            |-- inkscapeMadeEasy_Plot.py
            |-- textextLib
            |   |-- __init__.py
            |   |-- basicLatexPackages.tex
            |   |-- textext.inx
            |   |-- textext.py
            |
            |-- cartesianPlotData2D.py
            `-- cartesianPlotData2D.inx

Disabling LaTeX support of inkscapeMadeEasy

Many of the methods implemented in inkscapeMadeEasy project use LaTeX to generate text. To this end I decided to employ the excellent extension textext from Pauli Virtanen https://pav.iki.fi/software/textext/.

LaTeX support via textext extension requires LaTeX typesetting system in your computer (it's free and awesome! =] ), together with a few python modules (pygtk and Tkinter among others). The later might be a problem for non-Linux systems (precompiled inkscape for Windows as OS X don't come with them).

Since many people don't use LaTeX and/or don't have it installed, inkscapeMadeEasy's LaTeX support is now optional. By default, LaTeX support is ENABLED.

Please refer to https://fsmmlk.github.io/inkscapeMadeEasy/#installation-and-requirements on how to easily disable LaTeX support.

.. warning:: Since disabling LaTeX support is a new feature, this project was not yet extensively checked for misplacements/errors when this support is disabled. Please report any issues you find.

Usage

The extension can be found under extensions > fsmMLK > Plot 2D > Cartesian menu.

This extension is presented in two tabs, General Config and Axes configuration. The first is used to pass the data set and provide general configuration options. The second is used to configure the axes.

The General Config tab

Here you can define your data set and set several general parameters.

X/Y values: Strings containing the X,Y values of the points. The values MUST be separated by space. You must provide the same number of elements in 'X values' and 'Y values'

Attention: The extension will not check whether the points are valid.

Read data from file: If you toggle this option, you can provide inkscape with a text file containing the data.

The text file must be organized as table of values. Each colum will be considered a set of Y data. All columns must have the same number of lines.

The file can have one header with an arbitrary number of lines. In such case, you must inform the number of lines to be skipped (see below).

The separator can be any character, except the following characters: . (dot), + (plus), -(minus), E, e. The values can be integer or float values in decimal or exponential notation (e.g. the value 120 can also be given as 1.2e+2)

Attention: The decimal separator must be . (dot). If your computer uses comma, you should fix you computer =]

Example 1: (delimited by spaces)

-2 4
-1 2
 0 0
 1 2
 2 4

the extension will create two plots.

Example 2: (delimited by semicolons, with a header containing 3 lines)

Hello, this is my header
second line
another one!
-2;4;0
-1;2;1
 0;0;2
 1;2;3
 2;4;4

the extension will create two graphs, where:

  • the first plot will employ the first column as X data and the second as Y data
  • the second plot will employ the first column as X data and the third as Y data

Obs: Keep in mind that all plots will be placed at the center of your screen. You will have to move them in your document.

Directory name: Directory path of the input file. Enter preferably the full path of the directory

File name: Name of the file.

Delimiter character: Character used to delimit the columns of the file. If no character is informed, space is assumed

Skip header lines: Toggle to inform that the file contains a header.

Header's number of lines: Number of lines to be skipped in the header.

Use ellipsis marks at the ends: Use ellipsis marks at the end of the plots to indicate continuation

Draw Cartesian plane for each data set: This option affects only multiple plots via input file. If toggled, each plot will have its own Cartesian plane. Otherwise only the first plot will have it.

General aspect factor: General aspect ratio between line widths and text width. I designed this extension to have an overall aspect ratio that looked nice to my eyes. It is a function of X and Y tick lengths. With this control you can scale both line widths and text height to fit your needs.

Use custom output range: Toggle custom Y axis range of values.

Y min and Y max: (linear scale only) Set limits to the Y axis, despite of the data. The extension will inform if these limits are invalid. These values are used to limit the plot area along Y direction. For example, if your Ydata has values that do not lie within Ymin and Ymax, then the plot will be clipped at these values. A text element will be added to the document informing it.

The Axes Configuration tab

X/Y axis label: label of the axes. This string must be LaTeX compatible. Any LaTeX commands or environments are valid. If you want to write in mathematical environment, enclose your text with $...$. You don't have to escape any backslashes.

Tip: Since siunitx package is included in basicLatexPackages.tex file by default in inkscapeMadeEasy, you can use any unit command available there

Ex: Foobar $\sqrt{x^2}$ so fancy! (\si{\newton\per\squaremetre})

Logarithmic scale: Set the axis to be represented in log10 scale.

Add grid to X/Y axis: Draw grid lines in X or Y axes.

  • linear scale: The grid lines will be placed at each tick mark
  • logarithmic scale: The grid lines will be placed dividing each decade in 10 parts

Add ticks to X/Y axis: Draw tick marks with associated values in X or Y axes.

X/Y tick step: Tick marks interval in units of your chart. This value is not referenced to in logarithmic scale

Ex: limits from -1 to 1, with tick step of 0.5 will produce ticks at -1, -0.5, 0, 0.5, 1

Note: The ticks will radiate from the origin x=0 or y=0 unless the origin does not lie within the limits. In such cases, the ticks will radiate starting from the limit closest to the origin.

Examples in x direction. The same rules apply to Y direction

X/Y tick length The distance between the tick marks, in px.

  • linear scale: The distance between ticks in px.
  • logarithmic scale: The size of each decade in px.

X/Y tick suffix value: Optional extra suffix to be added to the tick values. You can use any LaTeX text/commands valid in mathematical environment $...$. You don't have to enclose your text between $...$. You don't have to escape any backslashes.

Observations

  • Since the plot is generated by connecting the points by a polyline, if your function is discontinuous your plot will present a line connecting both sides of the discontinuity. In such cases, please check your plot! ;)

  • This extension does not check if your data has NaN or Inf values. Check your data.

  • The axes will be placed crossing the origin (0,0) or crossing the coordinate (x,y) closest to the origin if the origin does not lies within the limits.

  • The axes will be created at the center of your screen.

Examples