12. mpl

This is a rudimentary interface to matplotlib to use dataArrays easier. The standard way to use matplotlib is full available without using this module..

The intention is to allow fast/easy plotting (one command to plot) with some convenience function in relation to dataArrays and in a non blocking mode of matplotlib. E.g. to include automatically the value of an attribute (qq in example) in the legend:

fig[0].Plot(mydataArray, legend='sqr=$qq',sy=[2,3,-1],li=0)
# dataList
fig[0].Plot(mydataList , legend='sqr=$qq',sy=[2,3,-1],li=0)

With somehow shorter form to determine the marker (sy=symbol) and line (li) and allow plotting in one line. Matplotlib is quite slow (and looks for me ugly). For 2D plotting use xmgrace. For 3D plotting this will give some simple plot options (planned).

  • The new methods introduced all start with a big Letter to allow still the access of the original methods.
  • By indexing subplots can be accessed as figure[i] which is figure.axes[i].
  • Same for axes with lines figure[0][i] is figure.axes[0].lines[i].

Example 1:

import jscatter as js
import numpy as np
i5=js.dL(js.examples.datapath+'/iqt_1hho.dat')
p=js.mplot()
p[0].Plot(i5,sy=[-1,0.4,-1],li=1,legend='Q= $q')
p[0].Yaxis(scale='l')
p[0].Title('intermediate scattering function')
p[0].Legend(x=1.13,y=1) # x,y in relative units of the plot
p[0].Yaxis(label='I(Q,t)/I(Q,0)',min=0.01)
p[0].Xaxis(label='Q / 1/nm',max=120)

Example 2 ( same as js.mpl.test() ):

import jscatter as js
import numpy as np
from matplotlib import pyplot
# use this
#fig=pyplot.figure(FigureClass=js.mpl.Figure)
# or
fig=js.mplot()
fig.Multi(2,1)
fig[0].SetView(0.1,0.25,0.8,0.9)
fig[1].SetView(0.1,0.09,0.8,0.23)
q=js.loglist(0.01,5,100)
aa=js.dL()
for pp in range(5):
    aa.append(js.dA(np.c_[q,-pp*np.sin(q),0.2*np.cos(5*q)].T))
    aa[-1].qq=pp
bb=js.dA(np.c_[q,q**2].T)
bb.qq=123
for pp in range(5):
    fig[0].Plot(aa[pp].X,-1*aa[pp].Y,legend='some stufff',sy=[1,(pp+1)/10.],li=0)

fig[0].Plot(aa, legend='qq = $qq', sy=[-1, 0.4, -1, ''], li=0, markeredgewidth=1)
for pp in range(5):
    fig[1].Plot(aa[-1].X/5+pp,pp*aa[-1].Y,legend='q=%.1f' %pp,sy=0,li=-1,markeredgewidth =1)
fig[1].Plot(bb,legend='sqr=$qq ',sy=2,li=2)
fig[0].Title('test')
fig[0].Legend(x=1.3,y=1)
fig[1].Legend(x=1.3,y=1)
fig[0].Yaxis(label='y-axis')
fig[1].Yaxis(label='something else')
fig[0].tick_params(labelbottom=False)
fig[1].Xaxis(label='x-axis')

12.1. Plot

mplot([width, height]) Open matplotlib figure in interactive mode with mplot.jsFigure and mplot.jspaperAxes.
surface(x, y, z[, xdim, levels, colorMap, …]) Surface plot of x,y,z, data
scatter3d(x[, y, z, pointsize, color]) Scatter plot of x,y,z data points.
contourImage(x[, y, z, xdim, levels, …]) Image with contour lines of x,y,z arrays with ndim=1 or 2.
showColors() Get a list of the colormaps in matplotlib.
test([keepopen]) A small test for mpl module making a plot.

12.2. Figures

class jscatter.mpl.jsFigure(*args, **kwargs)[source]

Create figure with Axes as jspaperAxes projection.

Examples

import jscatter as js
import numpy as np
i5=js.dL(js.examples.datapath+'/iqt_1hho.dat')
p=js.mplot()
p[0].Plot(i5,sy=[-1,0.4,-1],li=1,legend='Q= $q')
p[0].Yaxis(scale='l')
p[0].Title('intermediate scattering function')
p[0].Legend(x=1.13,y=1) # x,y in relative units of the plot
p[0].Yaxis(label='I(Q,t)/I(Q,0)',min=0.01)
p[0].Xaxis(label='Q / 1/nm',max=120)
jsFigure.Multi(n, m) Creates multiple subplots on grid n,m.
jsFigure.Addsubplot([bbox]) Add a subplot in the foreground.
jsFigure.Plot(*args, **kwargs)
jsFigure.Clear() Clear content of all axes
jsFigure.Save(filename[, format, dpi]) Save with filename
jsFigure.is_open() Is the figure window still open.
jsFigure.Exit()

12.3. Axes

class jscatter.mpl.jspaperAxes(*args, **kwargs)[source]

An Axes that should look like typical paper layout.

jspaperAxes.Plot(*datasets, **kwargs) Plot dataArrays/dataList or array in matplotlib axes.
jspaperAxes.Yaxis([min, max, label, scale, …]) Set xaxis
jspaperAxes.Xaxis([min, max, label, scale, …]) Set xaxis
jspaperAxes.Legend(**kwargs) Show/update legend.
jspaperAxes.Title(title[, size]) set Axes title
jspaperAxes.Subtitle(subtitle[, size]) Append subtitle to title
jspaperAxes.SetView([xmin, ymin, xmax, ymax]) This sets the bounding box of the axes.
jspaperAxes.Clear() Clear content of this axes.
jspaperAxes.Text(string, x, y, **kwargs)
jspaperAxes.Arrow([x1, y1, x2, y2, …]) Plot an arrow or line.

This is a rudimentary interface to matplotlib to use dataArrays easier. The standard way to use matplotlib is full available without using this module..

The intention is to allow fast/easy plotting (one command to plot) with some convenience function in relation to dataArrays and in a non blocking mode of matplotlib. E.g. to include automatically the value of an attribute (qq in example) in the legend:

fig[0].Plot(mydataArray, legend='sqr=$qq',sy=[2,3,-1],li=0)
# dataList
fig[0].Plot(mydataList , legend='sqr=$qq',sy=[2,3,-1],li=0)

With somehow shorter form to determine the marker (sy=symbol) and line (li) and allow plotting in one line. Matplotlib is quite slow (and looks for me ugly). For 2D plotting use xmgrace. For 3D plotting this will give some simple plot options (planned).

  • The new methods introduced all start with a big Letter to allow still the access of the original methods.
  • By indexing subplots can be accessed as figure[i] which is figure.axes[i].
  • Same for axes with lines figure[0][i] is figure.axes[0].lines[i].

Example 1:

import jscatter as js
import numpy as np
i5=js.dL(js.examples.datapath+'/iqt_1hho.dat')
p=js.mplot()
p[0].Plot(i5,sy=[-1,0.4,-1],li=1,legend='Q= $q')
p[0].Yaxis(scale='l')
p[0].Title('intermediate scattering function')
p[0].Legend(x=1.13,y=1) # x,y in relative units of the plot
p[0].Yaxis(label='I(Q,t)/I(Q,0)',min=0.01)
p[0].Xaxis(label='Q / 1/nm',max=120)

Example 2 ( same as js.mpl.test() ):

import jscatter as js
import numpy as np
from matplotlib import pyplot
# use this
#fig=pyplot.figure(FigureClass=js.mpl.Figure)
# or
fig=js.mplot()
fig.Multi(2,1)
fig[0].SetView(0.1,0.25,0.8,0.9)
fig[1].SetView(0.1,0.09,0.8,0.23)
q=js.loglist(0.01,5,100)
aa=js.dL()
for pp in range(5):
    aa.append(js.dA(np.c_[q,-pp*np.sin(q),0.2*np.cos(5*q)].T))
    aa[-1].qq=pp
bb=js.dA(np.c_[q,q**2].T)
bb.qq=123
for pp in range(5):
    fig[0].Plot(aa[pp].X,-1*aa[pp].Y,legend='some stufff',sy=[1,(pp+1)/10.],li=0)

fig[0].Plot(aa, legend='qq = $qq', sy=[-1, 0.4, -1, ''], li=0, markeredgewidth=1)
for pp in range(5):
    fig[1].Plot(aa[-1].X/5+pp,pp*aa[-1].Y,legend='q=%.1f' %pp,sy=0,li=-1,markeredgewidth =1)
fig[1].Plot(bb,legend='sqr=$qq ',sy=2,li=2)
fig[0].Title('test')
fig[0].Legend(x=1.3,y=1)
fig[1].Legend(x=1.3,y=1)
fig[0].Yaxis(label='y-axis')
fig[1].Yaxis(label='something else')
fig[0].tick_params(labelbottom=False)
fig[1].Xaxis(label='x-axis')
jscatter.mpl.contourImage(x, y=None, z=None, xdim=None, levels=8, fontsize=8, colorMap='jet', lineMap=None)[source]

Image with contour lines of x,y,z arrays with ndim=1 or 2.

Parameters:
x,y,z : arrays

x,y,z coordinates for z display. If x is 2D this is used.

xdim : int

If x,y,z are one dimensional xdim is dimension of first axis of x,y,z If None the number of unique values in x is used

levels : in, sequence of values

Number of contour lines between min and max or sequence of specific values.

colorMap : string

Get a colormap instance from name. Standard mpl colormap name (see showColors).

lineMap : string

Label color Colormap name as in colorMap, otherwise as cs in in Axes.clabel * if None, the color of each label matches the color of the corresponding contour * if one string color, e.g., colors = ‘r’ or colors = ‘red’, all labels will be plotted in this color * if a tuple of matplotlib color args (string, float, rgb, etc), different labels will be plotted in different colors in the order specified

fontsize : int

Size of line labels in pixel

Returns:
figure

Examples

  • Create use log scale for maksedArray (sasImage)

    import numpy as np
    # sets negative values to zero
    js.mpl.contourImage(np.ma.log(data))
    
jscatter.mpl.gf = 20

gracefactor to get same scaling as in grace set to 10

class jscatter.mpl.jsFigure(*args, **kwargs)[source]

Bases: matplotlib.figure.Figure

Create figure with Axes as jspaperAxes projection.

Examples

import jscatter as js
import numpy as np
i5=js.dL(js.examples.datapath+'/iqt_1hho.dat')
p=js.mplot()
p[0].Plot(i5,sy=[-1,0.4,-1],li=1,legend='Q= $q')
p[0].Yaxis(scale='l')
p[0].Title('intermediate scattering function')
p[0].Legend(x=1.13,y=1) # x,y in relative units of the plot
p[0].Yaxis(label='I(Q,t)/I(Q,0)',min=0.01)
p[0].Xaxis(label='Q / 1/nm',max=120)
Addsubplot(bbox=(0.2, 0.2, 0.6, 0.6), *args, **kwargs)[source]

Add a subplot in the foreground.

Parameters:
bbox : rect [left, bottom, width, height]

Bounding box position and size.

Clear()[source]

Clear content of all axes

to clear axes use fig.clear()

Close()[source]

Close the figure

Exit()[source]
Legend(*args, **kwargs)[source]
Line(*args, **kwargs)[source]
Multi(n, m)[source]

Creates multiple subplots on grid n,m. with projection “jspaperAxes”.

Subplots can be accesses as fig[i]

Plot(*args, **kwargs)
Save(filename, format=None, dpi=None, **kwargs)[source]

Save with filename

Subtitle(*args, **kwargs)[source]
Text(*args, **kwargs)[source]
Title(*args, **kwargs)[source]
Xaxis(*args, **kwargs)[source]
Yaxis(*args, **kwargs)[source]
is_open()[source]

Is the figure window still open.

plot(*args, **kwargs)[source]
class jscatter.mpl.jspaperAxes(*args, **kwargs)[source]

Bases: matplotlib.axes._axes.Axes

An Axes that should look like typical paper layout.

Arrow(x1=None, y1=None, x2=None, y2=None, linewidth=None, arrow=None)[source]

Plot an arrow or line.

Parameters:
x1,y1,x2,y2 : float

Start/end coordinates in box units [0..1].

linewidth : float

Linewidth

arrow : int or [‘-‘,’->’,’<-‘,’<->’]

Type of arrow. If int it selects from [‘-‘,’->’,’<-‘,’<->’]

Clear()[source]

Clear content of this axes.

Legend(**kwargs)[source]

Show/update legend.

Parameters:
charsize, fontsize : int, default 12

Font size of labels

labelspacing : int , default =12

Spacing of labels

loc : int [0..10] default 1 ‘upper right’

Location specifier - ‘best’ 0, ‘upper right’ 1, ‘upper left’ 2, ‘lower left’ 3, ‘lower right’ 4,‘center left’ 6,

x,y : float [0..1]

Determines if both given loc and sets position in axes coordinates. Sets bbox_to_anchor=(x,y)

kwargs : kwargs of axes.legend

Any given kwarg overrides the previous

Plot(*datasets, **kwargs)

Plot dataArrays/dataList or array in matplotlib axes.

Parameters are passed to matplotlib.axes.Axes.plot

Parameters:
datasets : dataArray/dataList or 1D arrays
Datasets to plot.
  • Can be several dataArray/dataList (with .X, .Y and .eY) or 1D arrays (a[1,:],b[2,:]), but dont mix it.
  • If dataArray/dataList has .eY errors a errorbars are plotted.
  • If format strings are found only the first is used. symbol, line override this.
  • Only a single line for 1D arrays is allowed.
symbol,sy : int, list of float
  • [symbol,size,color,fillcolor,fillpattern] as [1,1,1,-1];
  • single integer to chose symbol eg symbol=3; symbol=0 switches off
  • negative increments from last
  • symbol => see Line2D.filled_markers
  • size => size in pixel
  • color => int in sequence = wbgrcmyk
  • fillcolor=None see color
  • fillpattern=None 0 empty, 1 full, ….test it
line,li : int, list of float or Line object
  • [linestyle,linewidth,color] as [1,1,’‘];
  • negative increments
  • single integer to chose linestyle line=1; line=0 switches of
  • linestyle int ‘-‘,’–’,’-.’,’:’
  • linewidth float increasing thickness
  • color see symbol color
errorbar,er : int or list of float or Errorbar object
  • [color,size] as [1,1]; no increment, no repeat
  • color int see symbol color, non-integer syncs to symbol color
  • size float default 1.0 ; smaller is 0.5
legend,le : string
  • determines legend for all datasets
  • string replacement: attr name prepended by ‘$’ (eg. ‘$par’) is replaced by value str(par1.flatten()[0]) if possible. $(par) for not unique names
errorbar,er : float
  • errorbar thickness, zero is no errorbar
Resetlast()[source]
SetView(xmin=None, ymin=None, xmax=None, ymax=None)[source]

This sets the bounding box of the axes.

Parameters:
xmin,xmax,ymin,ymax : float

view range

Subtitle(subtitle, size=None, **kwargs)[source]

Append subtitle to title

Text(string, x, y, **kwargs)[source]
Title(title, size=None, **kwargs)[source]

set Axes title

Xaxis(min=None, max=None, label=None, scale=None, size=None, charsize=None, tick=None, ticklabel=None, **kwargs)[source]

Set xaxis

Parameters:
label : string

Label

scale : ‘log’, ‘normal’

Scale

min,max : float

Set min and max of scale

size : int

Pixelsize of label

kwargs : kwargs of axes.set_xscale

Any given kwarg overrides the previous

Yaxis(min=None, max=None, label=None, scale=None, size=None, charsize=None, tick=None, ticklabel=None, **kwargs)[source]

Set xaxis

Parameters:
label : string

Label

scale : ‘log’, ‘normal’

Scale

min,max : float

Set min and max

size : int

Pixelsize of label

kwargs : kwargs of axes.set_xscale

Any given kwarg overrides the previous

linlog(*args, **kwargs)[source]
loglin(*args, **kwargs)[source]
name = 'paper'
plot(*datasets, **kwargs)[source]

Plot dataArrays/dataList or array in matplotlib axes.

Parameters are passed to matplotlib.axes.Axes.plot

Parameters:
datasets : dataArray/dataList or 1D arrays
Datasets to plot.
  • Can be several dataArray/dataList (with .X, .Y and .eY) or 1D arrays (a[1,:],b[2,:]), but dont mix it.
  • If dataArray/dataList has .eY errors a errorbars are plotted.
  • If format strings are found only the first is used. symbol, line override this.
  • Only a single line for 1D arrays is allowed.
symbol,sy : int, list of float
  • [symbol,size,color,fillcolor,fillpattern] as [1,1,1,-1];
  • single integer to chose symbol eg symbol=3; symbol=0 switches off
  • negative increments from last
  • symbol => see Line2D.filled_markers
  • size => size in pixel
  • color => int in sequence = wbgrcmyk
  • fillcolor=None see color
  • fillpattern=None 0 empty, 1 full, ….test it
line,li : int, list of float or Line object
  • [linestyle,linewidth,color] as [1,1,’‘];
  • negative increments
  • single integer to chose linestyle line=1; line=0 switches of
  • linestyle int ‘-‘,’–’,’-.’,’:’
  • linewidth float increasing thickness
  • color see symbol color
errorbar,er : int or list of float or Errorbar object
  • [color,size] as [1,1]; no increment, no repeat
  • color int see symbol color, non-integer syncs to symbol color
  • size float default 1.0 ; smaller is 0.5
legend,le : string
  • determines legend for all datasets
  • string replacement: attr name prepended by ‘$’ (eg. ‘$par’) is replaced by value str(par1.flatten()[0]) if possible. $(par) for not unique names
errorbar,er : float
  • errorbar thickness, zero is no errorbar
jscatter.mpl.mplot(width=None, height=None, **kwargs)[source]

Open matplotlib figure in interactive mode with mplot.jsFigure and mplot.jspaperAxes.

Parameters:
width,height : float

Size of plot in cm.

kwargs :

Keyword args of matplotlib.pyplot.figure .

Returns:
matplotlib figure

Notes

  • By indexing as the axes subplots can be accessed as figure[i] which is figure.axes[i].
  • Same for axes with lines figure[0][i] is figure.axes[0].lines[i].
  • Some methods with similar behaviour as in grace are defined (big letter commands)
  • matplotlib methods are still available (small letters commands)
jscatter.mpl.regrid(x, y, z, xdim=None)[source]

Make a meshgrid from XYZ data columns.

Parameters:
x,y,z : array like

Array like data should be quadratic or rectangular.

xdim : None, shape of first x dimension

If None the number of unique values in x is used as first dimension

Returns:
2dim arrays for x,y,z
jscatter.mpl.scatter3d(x, y=None, z=None, pointsize=3, color='k')[source]

Scatter plot of x,y,z data points.

Parameters:
x,y,z : arrays

Data to plot. If x.shape is Nx3 these points are used.

pointsize : float

Size of points

color : string

Colors for points

Returns:
figure
jscatter.mpl.showColors()[source]

Get a list of the colormaps in matplotlib.

Ignore the ones that end with ‘_r’ because these are simply reversed versions of ones that don’t end with ‘_r’

Colormaps Names
Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap, CMRmap_r, Dark2, Dark2_r, GnBu, GnBu_r, Greens, Greens_r, Greys, Greys_r, OrRd, OrRd_r, Oranges, Oranges_r, PRGn, PRGn_r, Paired, Paired_r, Pastel1, Pastel1_r, Pastel2, Pastel2_r, PiYG, PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr, PuOr_r, PuRd, PuRd_r, Purples, Purples_r, RdBu, RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu, RdYlBu_r, RdYlGn, RdYlGn_r, Reds, Reds_r, Set1, Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral, Spectral_r, Vega10, Vega10_r, Vega20, Vega20_r, Vega20b, Vega20b_r, Vega20c, Vega20c_r, Wistia, Wistia_r, YlGn, YlGnBu, YlGnBu_r, YlGn_r, YlOrBr, YlOrBr_r, YlOrRd, YlOrRd_r, afmhot, afmhot_r, autumn, autumn_r, binary, binary_r, bone, bone_r, brg, brg_r, bwr, bwr_r, cool, cool_r, coolwarm, coolwarm_r, copper, copper_r, cubehelix, cubehelix_r, flag, flag_r, gist_earth, gist_earth_r, gist_gray, gist_gray_r, gist_heat, gist_heat_r, gist_ncar, gist_ncar_r, gist_rainbow, gist_rainbow_r, gist_stern, gist_stern_r, gist_yarg, gist_yarg_r, gnuplot, gnuplot2, gnuplot2_r, gnuplot_r, gray, gray_r, hot, hot_r, hsv, hsv_r, inferno, inferno_r, jet, jet_r, magma, magma_r, nipy_spectral, nipy_spectral_r, ocean, ocean_r, pink, pink_r, plasma, plasma_r, prism, prism_r, rainbow, rainbow_r, seismic, seismic_r, spectral, spectral_r, spring, spring_r, summer, summer_r, tab10, tab10_r, tab20, tab20_r, tab20b, tab20b_r, tab20c, tab20c_r, terrain, terrain_r, viridis, viridis_r, winter, winter_r

From https://matplotlib.org/1.2.1/examples/pylab_examples/show_colormaps.html

jscatter.mpl.surface(x, y, z, xdim=None, levels=8, colorMap='jet', lineMap=None, alpha=0.7)[source]

Surface plot of x,y,z, data

Parameters:
x,y,z : array

Data as array

xdim : integer

First dimension of x

levels : integer, array

Levels for contour lines as number of levels or array of specific values.

colorMap : string

Color map name, see showColors.

lineMap : string
Color name for contour lines

b: blue g: green r: red c: cyan m: magenta y: yellow k: black w: white

alpha : float [0,1], default 0.7

Transparency of surface

Returns:
figure
jscatter.mpl.test(keepopen=True)[source]

A small test for mpl module making a plot.

Examples

import jscatter as js
import numpy as np
from matplotlib import pyplot
# use this
#fig=pyplot.figure(FigureClass=js.mpl.Figure)
# or
fig=js.mplot()
fig.Multi(2,1)
fig[0].SetView(0.1,0.25,0.8,0.9)
fig[1].SetView(0.1,0.09,0.8,0.23)
q=js.loglist(0.01,5,100)
aa=js.dL()
for pp in range(5):
    aa.append(js.dA(np.c_[q,-pp*np.sin(q),0.2*np.cos(5*q)].T))
    aa[-1].qq=pp
bb=js.dA(np.c_[q,q**2].T)
bb.qq=123
for pp in range(5):
    fig[0].Plot(aa[pp].X,-1*aa[pp].Y,legend='some stufff',sy=[1,(pp+1)/10.],li=0)

fig[0].Plot(aa, legend='qq = $qq', sy=[-1, 0.4, -1, ''], li=0, markeredgewidth=1)
for pp in range(5):
    fig[1].Plot(aa[-1].X/5+pp,pp*aa[-1].Y,legend='q=%.1f' %pp,sy=0,li=-1,markeredgewidth =1)
fig[1].Plot(bb,legend='sqr=$qq ',sy=2,li=2)
fig[0].Title('test')
fig[0].Legend(x=1.3,y=1)
fig[1].Legend(x=1.3,y=1)
fig[0].Yaxis(label='y-axis')
fig[1].Yaxis(label='something else')
fig[0].tick_params(labelbottom=False)
fig[1].Xaxis(label='x-axis')