Tutorial

The package is based on two classes, DataSet and Plot. Each DataSet class holds cartesian coordinates and the intended plot type. These sets can then be added to a Plot object, which handles the plotting process.

In general the package is designed to produce nice plots with as few settings as possible, but also for plots to be fully customisable if required.

The DataSet Class

A simple example of of making two data sets is as follows:

import numpy as np
from mpl_scipub.dataset import DataSet

# Generate data
cosine = np.zeros((100,2))
cosine[:,0] = np.linspace(0,10,100)
cosine[:,1] = np.cos(cosine[:,0])

random = np.zeros((50,2))
random[:,0] = np.random.uniform(0,10,50)
random[:,1] = np.random.uniform(-1,1,50)
random_size = np.random.uniform(5,50,50)
random_colour = np.random.uniform(0,1,50)

# Make DataSet specifying properties on instantiation
dataset_a = DataSet(cosine, plot='line', label='cosine', colour='black', line_width=2)

# Make DataSet specifiying properties through setters
dataset_b = DataSet(random, plot='scatter', label='random')
dataset_b.set_marker(style='o',size=random_size)
dataset_b.set_colour(map='coolwarm',colour=random_colour)

The list of methods is given below.

class mpl_scipub.dataset.DataSet(data, **kwargs)[source]

Holds data set and associated plot options.

__init__(data, **kwargs)[source]

Data as numpy array. Format depends on plot type but usually (n_points,2) for 2D plot and (n_points,3) for 3D plot. Can specifiy plot options through kwargs now, or later through setters.

Parameters:
  • data (np.ndarray) – x,y,(z) data
  • error_y (np.ndarray with n_points) – symmetric errors in given direction
  • error_width (float) – width of error bars
  • error_interval (int) – errors every n points
  • error_cap (int) – error cap size
  • plot (str) – type of plot (line, scatter, bar ,error_bar, error_shade, heat, contour)
  • label (str) – data label for legend
  • order (int) – ordering of overlaid datasets, higher number on top
  • line_style (str) – line style (-,–,:,etc.)
  • int (line_width,) – line width
  • marker_style (int) – marker style
  • marker_size (float or np.ndarray) – fixed size for marker or array of sizes
  • bar_width (float) – width of each bar in bar graph
  • contour_levels (np.ndarray) – specified levels to draw contours
  • contour_number (int) – number of contours to draw if levels not supplied
  • contour_limits (tuple) – lower and upper bounds for contours
  • colour (str or np.ndarray) – colour code for all data points or array of floats if using colour map
  • colour_map (str) – colour map
  • colour_norm (tuple) – normalisation condition for colour map
  • surface_interpolation (str) – interpolation type for surface plots
set_bar(width=1)[source]

Set bar width.

set_colour(colour=None, map=None, norm=None)[source]

Set colour as individual or map.

set_contours(levels=None, number=10, limits=None)[source]

Set contour properties.

set_error(width=None, interval=1, cap=1)[source]

Set error width, interval and capsize

set_line(style='-', width=2)[source]

Set line style and width.

set_marker(style=None, size=10)[source]

Set marker style and size.

The Plot Class

The data sets abbove can be plotted using the plot class as follows:

from mpl_scipub.plotter import Plot

# Make Plot class and add DataSets
plot = Plot()
plot.add_dataset(dataset_a)
plot.add_dataset(dataset_b)

# Adjust plot properties
plot.set_axes(xlim=(0,10),xticks=(1,0.2),yticks=(0.2,0.05),xlabel=r'$x$',ylabel=r'$f\left(x\right)$') # Latex-style labels

# Plot graphs
plot.plot()
plot.save(fmt='png')
plot.display()
_images/tutorial.png

The list methods is given below.

class mpl_scipub.plotter.Plot(dim=2, elevation=20, angle=130)[source]

Plot DataSet objects with matplotlib.

add_dataset(dataset)[source]

Add DataSet object.

display()[source]

Display figure.

plot()[source]

Plot graphs.

save(name='plot', fmt='pdf', dpi_quality=400)[source]

Save figure.

set_axes(**kwargs)[source]

Sets axes properties for x,y,z axes.

Parameters:
  • xlabel (str) – x-axis label
  • xlim (tuple) – x-axis limits
  • xticks (tuple) – positions of major and minor ticks
  • xlog (bool) – use logarithmic scale for x-axis
set_dimensions(dim=2)[source]

Set dimensionality of plot.

set_legend(**kwargs)[source]

Set legend properties.

Parameters:
  • legend (bool) – turn legend on or off
  • title (str) – set legend title
  • columns (int) – number of columns in legend
  • reverse (bool) – reverse order of legend
  • location (str) – location (‘upper left’ etc.)
set_plot_size(width=4, height=4)[source]

Set plot size in cm.

set_text(font='serif', latex=False, legend=10, title=10, label=10)[source]

Set font and text size. :param latex: enable latex formatting - this is slower to render image but can give better fonts :type latex: bool

set_view(elevation=None, angle=None)[source]

Set view in 3D plot.