qharv.field package

Submodules

qharv.field.kyrt module

qharv.field.kyrt.cox(ax, x, xtlabels)[source]

Add co-xticklabels at top of the plot, e.g., with a different unit

Parameters
  • ax (plt.Axes) – matplotlib axes

  • x (list) – xtick locations

  • xtlabels (list) – xtick labels

qharv.field.kyrt.coy(ax, y, ytlabels)[source]

Add co-yticklabels on the right of the plot, e.g., with a different unit

Parameters
  • ax (plt.Axes) – matplotlib axes

  • y (list) – ytick locations

  • ytlabels (list) – ytick labels

qharv.field.kyrt.create_legend(ax, styles, labels, **kwargs)[source]

create custom legend

learned from “Composing Custom Legends”

Parameters

ax (plt.Axes) – matplotlib axes

Returns

legend artist

Return type

plt.legend.Legend

qharv.field.kyrt.errorshade(ax, x, ym, ye, **kwargs)[source]
qharv.field.kyrt.figaxad(labelsize=12)[source]
construct a absolute/difference (ad) figure

top 3/4 of the plot will be comparison at an absolute scale bottom 1/4 of the plot will be comparison at a relative scale

Parameters

labelsize (int, optional) – tick label size

Returns

figure and axes for absolute and difference plots

Return type

(fig, axa, axd)

qharv.field.kyrt.get_cmap(name='viridis')[source]

return color map by name

Parameters

name (str, optional) – name of color map, default ‘viridis’

Returns

requested colormap

Return type

matplotlib.colors.ListedColormap

qharv.field.kyrt.get_norm(vmin, vmax)[source]

return norm function for scalar in range (vmin, vmax)

Parameters
  • vmin (float) – value minimum

  • vmax (float) – value maximum

Returns

color normalization function

Return type

matplotlib.colors.Normalize

qharv.field.kyrt.get_style(line)[source]

get plot styles from Line2D object

mostly copied from “Line2D.update_from”

Parameters

line (Line2D) – source of style

Returns

line styles readily usable for another plot

Return type

dict

qharv.field.kyrt.gpr_errorshade(ax, x, ym, ye, length_scale, noise_level, fb_kwargs=None, **kwargs)[source]

WARNING: length_scale and noise_level are VERY DIFFICULT to tune

qharv.field.kyrt.inset_zoom(fig, ax_box, xlim, ylim, draw_func, xy_label=False)[source]

show an inset that zooms into a given part of the figure

Parameters
  • fig (plt.Figure) – figure

  • ax_box (tuple) – inset location and size (x0, y0, dx, dy) in figure ratio

  • xlim (tuple) – (xmin, xmax)

  • ylim (tuple) – (ymin, ymax)

  • draw_func (callable) – draw_func(ax) should recreate the figure

  • xy_label (bool, optional) – label inset axes, default is False

Returns

inset axes

Return type

plt.Axes

Example

>>> ax1 = inset_zoom(fig, [0.15, 0.15, 0.3, 0.3], [0.1, 0.5], [-0.02, 0.01],
>>>                  lambda ax: ax.plot(x, y))
>>> ax.indicate_inset_zoom(axins)
qharv.field.kyrt.krig(finex, x0, y0, length_scale, noise_level)[source]
qharv.field.kyrt.pretty_up(ax)[source]
qharv.field.kyrt.scalar_colorbar(vmin, vmax, name='viridis', **kwargs)[source]

return a colorbar for scalar_color_map()

Parameters
  • vmin (float) – minimum scalar value

  • vmax (float) – maximum scalar value

  • name (str, optional) – color map name, default is ‘viridis’

Returns

colorbar

Return type

matplotlib.colorbar.Colorbar

qharv.field.kyrt.scalar_colormap(vmin, vmax, name='viridis')[source]

return a function that maps a number to a color

Parameters
  • vmin (float) – minimum scalar value

  • vmax (float) – maximum scalar value

  • name (str, optional) – color map name, default is ‘viridis’

Returns

float -> (float,)*4 RGBA color space

Return type

function

qharv.field.kyrt.set_label_font(ax, xsize=14, ysize=14, xweight='bold', yweight='bold', **kwargs)[source]

change x,y label fonts

Parameters
  • ax (plt.Axes) – matplotlib axes

  • xsize (int,optional) – xlabel fontsize, default is 14

  • ysize (int,optional) – ylabel fontsize, default is 14

  • xweight (str,optional) – xlabel fontweight, default is ‘bold’

  • yweight (str,optional) – ylabel fontweight, default is ‘bold’

  • kwargs (dict) – other label-related properties

qharv.field.kyrt.set_legend_marker_size(leg, ms=10)[source]
qharv.field.kyrt.set_style(style='ticks', context='talk', **kwargs)[source]
qharv.field.kyrt.set_tick_font(ax, xsize=14, ysize=14, xweight='bold', yweight='bold', **kwargs)[source]

change x,y tick fonts

Parameters
  • ax (plt.Axes) – matplotlib axes

  • xsize (int,optional) – xtick fontsize, default is 14

  • ysize (int,optional) – ytick fontsize, default is 14

  • xweight (str,optional) – xtick fontweight, default is ‘bold’

  • yweight (str,optional) – ytick fontweight, default is ‘bold’

  • kwargs (dict) – other tick-related properties

qharv.field.kyrt.set_xy_format(ax, xfmt='%3.2f', yfmt='%3.2f')[source]

change x,y tick formats e.g. number of digits

Parameters
  • ax (plt.Axes) – matplotlib axes

  • xfmt (int,optional) – xtick format, default is ‘%3.2f’

  • yfmt (int,optional) – ytick format, default is ‘%3.2f’

qharv.field.kyrt.show_fit(ax, line, model, sel=None, nx=64, popt=None, xmin=None, xmax=None, circle=True, circle_style=None, cross=False, cross_style=None, **kwargs)[source]

fit a segment of (x, y) data and show fit

get x, y data from line; use sel to make selection

Parameters
  • ax (Axes) – matplotlib axes

  • line (Line2D) – line with data

  • model (callable) – model function

  • sel (np.array, optional) – boolean selector array

  • nx (int, optional) – grid size, default 64

  • xmin (float, optional) – grid min

  • xmax (float, optional) – grid max

  • circle (bool, optional) – circle selected points, default True

  • cross (bool, optional) – cross out deselected points, default False

Returns

(popt, perr, lines)

Return type

(np.array, np.array, list)

qharv.field.kyrt.show_spline(ax, line, spl_kws={}, sel=None, **kwargs)[source]

show a smooth spline through given line x y

Parameters
  • ax (plt.Axes) – matplotlib axes

  • line (Line1D) – matplotlib line object

  • spl_kws (dict, optional) – keyword arguments to splrep, default is empty

  • nx (int, optional) – number of points to allocate to 1D grid

Returns

interpolating line

Return type

Line1D

qharv.field.kyrt.smooth_bspline(myx, myy, nxmult=10, **spl_kws)[source]
qharv.field.kyrt.xtop(ax)[source]

move xaxis label and ticks to the top

Parameters

ax (plt.Axes) – matplotlib axes

qharv.field.kyrt.yright(ax)[source]

move yaxis label and ticks to the right

Parameters

ax (plt.Axes) – matplotlib axes

qharv.field.sugar module

qharv.field.sugar.cache(write_file)[source]
qharv.field.sugar.check_dir_before(mkdir)[source]
qharv.field.sugar.concat_return(show_progress=True, fault_tolerant=False)[source]

Show progress of concat reduce function

qharv.field.sugar.get_progress_bar(maxval)[source]
qharv.field.sugar.mkdir(dirname)[source]
qharv.field.sugar.show_h5progress(collect_h5file)[source]
qharv.field.sugar.skip_exist_file(write_file)[source]

Module contents