dautil.plotting

This module contains plotting utilities.

class dautil.plotting.CyclePlotter(ax)

A plotter which cycles through different linestyle and linewidth values.

Variables:
  • ax – A SubplotAxes instance.
  • cycler – A Cycler instance.
plot(x, y=None, *args, **kwargs)

A facade for the matplotlib plot() method.

Parameters:
  • x – Array of ‘x’ values for the plot.
  • y – Array of ‘y’ values for the plot.
class dautil.plotting.Cycler(styles=['-', '--', '-.', ':'], lw=[1, 2])

Utility class, which cycles through values of plotting related lists.

Variables:
  • STYLES – A list of line styles.
  • LW – A list of linewidths.
  • colors – A list of colors.
color()

Cycles through a list of colors.

Returns:The next color in the list.
lw()

Cycles through a list of linewidth values.

Returns:The next linewidth in the list.
style()

Cycles through a list of line styles.

class dautil.plotting.Subplotter(nrows=1, ncols=1, context=None)

A utility to help with subplotting.

Variables:
  • context – A Context instance.
  • index – The index of the subplot.
  • ax – The current SubplotAxes instance.
exit(mark=True)

Cleans up the Subplotter.

Parameters:mark – Boolean indicating whether to apply watermark.
Returns:The appropriate watermark.
get_string(old, key, params)

Gets a string used to label x-axis, y-axis or title of a subplot.

Parameters:
  • old – Configuration setting from a file.
  • key – title, xlabel, legend or ylabel.
  • params – Extra params provided for the

Python string format() method. We expect the appropriate use of curly braces.

Returns:A (formatted) string for the x-axis,

y-axis, legend or title of a subplot.

label(advance=False, title_params=None, xlabel_params=None, ylabel_params=None)

Labels the subplot.

Parameters:
  • advance – Boolean indicating whether to move to the next subplot.
  • title_params – Optional title parameters.
  • xlabel_params – Optional xlabel parameters.
  • ylabel_params – Optional ylabel parameters.
next_ax()

Advance to next subplot.

Returns:The current subplot after advancing.
dautil.plotting.all_markers()

Gets all the matplotlib markers except None.

Returns:The matplotlib marker character codes except the None markers.
dautil.plotting.bar(ax, xlabels, vals)

Plots a bar chart.

Parameters:
  • ax – A SubplotAxes object.
  • xlabels – Labels on the x-axis.
  • vals – Values for the bars.
dautil.plotting.embellish(axes, legends=None)

Adds grid and legends to matplotlib plots.

Parameters:
  • axes – Axes as returned by the plt.subplots() function.
  • legends – A list of indices of subplots, which need a legend.
dautil.plotting.hide_axes(axes)

Hides the x-axis and y-axis of matplotlib plots.

Parameters:axes – Axes as returned by the plt.subplots() function.
dautil.plotting.hist_norm_pdf(ax, arr)

Plots a histogram with corresponding normal PDF.

Parameters:
  • ax – A SubplotAxes object.
  • arr – Values for the histogram.
dautil.plotting.img_show(ax, img, *args, **kwargs)

Plots an image with axes turned off.

Parameters:
  • ax – A SubplotAxes object.
  • img – The image to display.
dautil.plotting.map_markers(vals)

Maps matplotlib markers to values.

Parameters:vals – Values to map.
Returns:A list where each value is replaced by a marker character code.
dautil.plotting.plot_points(ax, points)

Plots points with the ‘o’ marker and as a line.

Parameters:
  • ax – A SubplotAxes object to draw on.
  • points – A list of points as the following: [(x1, y1), (x2, y2), ...]
dautil.plotting.plot_polyfit(ax, x, y, degree=1, plot_points=False)

Plots a polynomial fit.

Parameters:
  • ax – A matplotlib SubplotAxes object.
  • x – An array of ‘x’ values.
  • y – An array of ‘y’ values.
  • degree – The polynomial degree.
  • plot_points – Whether to plot points.
dautil.plotting.plot_text(ax, xcoords, ycoords, point_labels, add_scatter=False, *args, **kwargs)

Plots text labels with given coordinates.

Parameters:
  • ax – A SubplotAxes object.
  • xcoords – Array-like x coordinates.
  • ycoords – Array-like y coordinates.
  • point_labels – Text labels to put on the chart.
  • add_scatter – Whether to scatter plot the coordinate values.
dautil.plotting.sample_cmap(name='Reds', start=0.1, end=0.9, ncolors=9)

Samples a matplotlib color map using a linearly spaced range.

Parameters:
  • name – Name of the color map.
  • start – Start of the linear range.
  • end – End of the linear range.
  • ncolors – The number of colors in the range.
Returns:

A sample of the color map.

>>> from dautil import plotting
>>> plotting.sample_cmap()
array([[ 0.99692426,  0.89619378,  0.84890428,  1.        ],
       [ 0.98357555,  0.41279508,  0.28835065,  1.        ],
       [ 0.59461747,  0.0461361 ,  0.07558632,  1.        ]])
dautil.plotting.sample_hex_cmap(name='Reds', start=0.1, end=0.9, ncolors=9)

Samples a matplotlib color map using a linearly spaced range and return hex values for the colors.

Parameters:
  • name – Name of the color map.
  • start – Start of the linear range.
  • end – End of the linear range.
  • ncolors – The number of colors in the range.
Returns:

A list of hex values from a sample of the color map.

>>> from dautil import plotting
>>> plotting.sample_hex_cmap()
['#fee5d8', '#fdcab5', '#fcab8f', '#fc8a6a', '#fb694a',
'#f14432', '#d92523', '#bc141a', '#980c13']
dautil.plotting.scatter_with_bar(ax, bar_label, *args, **kwargs)

Creates a matplotlib scatter plot with a colorbar.

Parameters:
  • ax – A matplotlib SubplotAxes.
  • bar_label – The label of the colorbar.

Previous topic

dautil.perf

Next topic

dautil.report

This Page