12. mpl — jscatter 0.6.6 documentation

# 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 in the legend:

    fig[0].Plot(mydataArray,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 (really not paper ready). 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 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].

Example 1:

    import jscatter as js
    import numpy as np
    i5=js.dL('exampleData/iqt_1hho.dat')
    p=js.mplot()
    p[0].Plot(i5,sy=[-1,4,-1],li=1,legend='Q= $q')
    p[0].Yaxis(scale='l')
    p[0].Title('intermediate scattering function')
    p[0].Legend()
    p[0].Yaxis(label='I(Q,t)/I(Q,0)')
    p[0].Xaxis(label='Q / 1/nm')

Example 2:

    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.7)
    fig[1].SetView(0.1,0.09,0.8,0.15)
    q=js.loglist(0.01,5,100)
    aa=js.dA(np.c_[q,np.sin(q),0.1*np.cos(q)].T)
    bb=js.dA(np.c_[q,q**2].T)
    bb.qq=123
    fig[0].Plot(aa,legend='sin',sy=2,li=3)
    for pp in range(10):  fig[0].Plot(aa.X,aa.Y*pp,legend='sin',sy=[-1,8,-1,''],li=0,markeredgewidth =1)
    fig[1].Plot(bb,legend='sqr=$qq ',sy=2,li=0)
    fig[0].Title('test')
    fig[0].Legend()
    fig[1].Legend()
    fig[0].Yaxis(label='y-axis')
    fig[1].Yaxis(label='Residuals')
    fig[1].Xaxis(label='x-axis')

## 12.1. Plot

`mplot`() | Open matplotlib figure in interactive mode.
`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
`contourImage`(x, y, z[, xdim, levels, …]) | Image with contour lines of x,y,z arrays with ndim=1 or 2.

## 12.2. Figures

class `jscatter.mpl.` `Figure`(*args, **kwargs)

`Figure.Multi`(n, m) | Creates multiple subplots on grid n,m.
`Figure.Clear`() | Clear content of all axes
`Figure.Save`(filename, format, size, dpi) | Save with filename
`Figure.is_open`() | Is the figure window still open.
`Figure.Exit`() |

## 12.3. Axes

class `jscatter.mpl.` `paperAxes`(fig, rect, facecolor=None, frameon=True, sharex=None, sharey=None, label=u'', xscale=None, yscale=None, axisbg=None, **kwargs)

  An Axes that default is close to paper quality output

`paperAxes.Plot`(*datasets, **kwargs) | plot dataArrays or array in matplotlib axes.
`paperAxes.Yaxis`([label, scale, min, max]) | set Yaxis
`paperAxes.Xaxis`([label, scale, min, max]) | set Xaxis
`paperAxes.Legend`(**kwargs) | Set axis legend; see Figure.legend
`paperAxes.Title`(title) | set Axes title
`paperAxes.Subtitle`(subtitle) | Append subtitle to title
`paperAxes.SetView`([xmin, ymin, xmax, ymax]) | this sets the viewport coords.
`paperAxes.Clear`() | Clear content of this axes

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 in the legend:

    fig[0].Plot(mydataArray,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 (really not paper ready). 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 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].

Example 1:

    import jscatter as js
    import numpy as np
    i5=js.dL('exampleData/iqt_1hho.dat')
    p=js.mplot()
    p[0].Plot(i5,sy=[-1,4,-1],li=1,legend='Q= $q')
    p[0].Yaxis(scale='l')
    p[0].Title('intermediate scattering function')
    p[0].Legend()
    p[0].Yaxis(label='I(Q,t)/I(Q,0)')
    p[0].Xaxis(label='Q / 1/nm')

Example 2:

    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.7)
    fig[1].SetView(0.1,0.09,0.8,0.15)
    q=js.loglist(0.01,5,100)
    aa=js.dA(np.c_[q,np.sin(q),0.1*np.cos(q)].T)
    bb=js.dA(np.c_[q,q**2].T)
    bb.qq=123
    fig[0].Plot(aa,legend='sin',sy=2,li=3)
    for pp in range(10):  fig[0].Plot(aa.X,aa.Y*pp,legend='sin',sy=[-1,8,-1,''],li=0,markeredgewidth =1)
    fig[1].Plot(bb,legend='sqr=$qq ',sy=2,li=0)
    fig[0].Title('test')
    fig[0].Legend()
    fig[1].Legend()
    fig[0].Yaxis(label='y-axis')
    fig[1].Yaxis(label='Residuals')
    fig[1].Xaxis(label='x-axis')

class `jscatter.mpl.` `Figure`(*args, **kwargs)

  Bases: `matplotlib.figure.Figure`

  `Clear`()

    Clear content of all axes

    to clear axes use fig.clear()

  `Close`()

    Close the figure

  `Exit`()
  `Multi`(n, m)

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

    Subplots can be accesses as fig[i]

  `Save`(filename, format, size, dpi)

    Save with filename

  `is_open`()

    Is the figure window still open.

`jscatter.mpl.` `contourImage`(x, y, z, xdim=None, levels=8, fontsize=8, colorMap='jet', lineMap=None)

  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 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 Notes). 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

  Notes

  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

`jscatter.mpl.` `gf` = 1

  gracefactor to get same scaling as in grace set to 10

`jscatter.mpl.` `mplot`()

  Open matplotlib figure in interactive mode.

  Returns: | pyplot 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].

class `jscatter.mpl.` `paperAxes`(fig, rect, facecolor=None, frameon=True, sharex=None, sharey=None, label=u'', xscale=None, yscale=None, axisbg=None, **kwargs)

  Bases: `matplotlib.axes._axes.Axes`

  An Axes that default is close to paper quality output

  `Clear`()

    Clear content of this axes

  `Legend`(**kwargs)

    Set axis legend; see Figure.legend

  `Plot`(*datasets, **kwargs)

    plot dataArrays or array in matplotlib axes.

    Parameters: | datasets : dataArray, dataList,numpy array, lists of them several of (comma separated) nonkeyword arguments or as list if dimension of datasets is one a new Data object is created and plotted see Notes below for error plots 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 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`()
  `SetView`(xmin=None, ymin=None, xmax=None, ymax=None)

    this sets the viewport coords.

    Parameters: | xmin,xmax,ymin,ymax : float view range

  `Subtitle`(subtitle)

    Append subtitle to title

  `Title`(title)

    set Axes title

  `Xaxis`(label=None, scale=None, min=None, max=None, **kwargs)

    set Xaxis

    Parameters: | label : string label scale : ‘log’, ‘normal’ min,max : float min and max of scale kwargs : kwargs of axes.set_xscale any given kwarg overrides the previous

  `Yaxis`(label=None, scale=None, min=None, max=None, **kwargs)

    set Yaxis

    Parameters: | label : string label scale : ‘log’, ‘normal’ min,max : float min and max of scale kwargs : kwargs of axes.set_xscale any given kwarg overrides the previous

  `name` = 'paper'

`jscatter.mpl.` `regrid`(x, y, z, xdim=None)

  Make a meshgrid from XYZ data columns.

  Parameters: | x,y,z : arary 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, z, pointsize=3, color='k')

  Scatter plot of X,Y,Z data

  Parameters: | x,y,z : arrays Data pointsize : float Size of points color : string Colors for points
  Returns: | figure

`jscatter.mpl.` `showColors`()

  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)

  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)

  A small test if this is working