rwth_nb.plots
RWTH Colors
This module defines rwth_colors following the 2013 RWTH corporate design (CD) color scheme. These colors are propagated to Matplotlib as well.
Matplotlib Decorations
Plot functions enhancing Matplotlib
- rwth_nb.plots.mpl_decorations.annotate_distance(ax, txt, start, stop, color='rwth:black', **kwargs)
Annotate distance between two points in given axis
Parameters
- ax: matplotlib.axes.Axes
current axis
- txt: str
distance annotation text
- start: (float, float)
x and y position of starting point
- stop: (float, float)
x and y position of ending point
- color: str, optional
annotations color
- **kwargs: dict
all additional keyword arguments are passed to distances and texts matplotlib.axes.Axes.annotate call
Returns
- distance: matplotlib.text.Annotation
annotation marking distance between the two points
- text: matplotlib.text.Annotation
annotated text
- rwth_nb.plots.mpl_decorations.annotate_xtick(ax, txt, x, y=0, col='black', fs=12)
Annotate certain tick on the x-axis
Parameters
- ax: matplotlib.axes.Axes
Current axes
- txt: string
Annotated text
- x: float [scalar]
x position of tick and txt
- y: float [scalar]
y position of txt
See Also
annotate_ytick: Annotates a tick on the y-axis
- rwth_nb.plots.mpl_decorations.annotate_ytick(ax, txt, x, y, col='black', fs=12)
Annotate certain tick on the y-axis
Parameters
- ax: matplotlib.axes.Axes
Current axes
- txt: string
Annotated text
- x: float [scalar]
x position of tick and txt
- y: float [scalar]
y position of txt
See Also
annotate_xtick: Annotates a tick on the x-axis
- rwth_nb.plots.mpl_decorations.axis(ax)
Decorate axes RWTH way.
Parameters
- ax: matplotlib.axes.Axes
Axes to be beautified
See Also
TODO
Notes
Nada.
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> import rwth_nb.plot.mpl_decorations as rwth_plt >>> >>> x = np.linspace(-5,5,100) >>> fig,ax = plt.subplots() >>> ax.plot(x, x**2) >>> ax.set_xlabel('x'); ax.set_ylabel('f(x)'); >>> rwth_plt.axis(ax)
- rwth_nb.plots.mpl_decorations.dirac_set_data(containers, x, y)
Change data in existing dirac containers
Parameters
- containers: Tuple of matplotlib.container.StemContainer class
Tuple containing both positive and negative dirac containers
- x: array-like
New dirac x positions
- y: array-like
New dirac weights
- rwth_nb.plots.mpl_decorations.dirac_weights(ax, x, y, weights, **kwargs)
Show diracs’ weights in a plot
Parameters
- ax: matplotlib.axes.Axes
Current axes
- x: array-like or scalar
Diracs’ x positions
- y: array-like or scalar
Diracs’ weights’ y-positions
- weights: array-like or scalar
Diracs’ weights
- **kwargs: dict
all additional keyword arguments are passed to matplotlib.axes.Axes.text call
- rwth_nb.plots.mpl_decorations.grid(ax)
Grid, but below axis
Parameters
- ax: matplotlib.axes.Axes
Current axes
- rwth_nb.plots.mpl_decorations.plot_dirac(ax, x, y, color='rwth:blue', **kwargs)
Custom dirac plot
Parameters
- ax: matplotlib.axes.Axes
Current axes
- x: array-like
Diracs’ x positions
- y: array-like
Diracs’ y-positions
- color: str, optional
Diracs’ colors
- **kwargs: dict
all additional keyword arguments are passed to rwth_nb.plots.mpl_decorations.stem call
Returns
- cp: instance of class matplotlib.container.StemContainer
Container for diracs with positive weights
- cn: instance of class matplotlib.container.StemContainer
Container for diracs with negative weights
- rwth_nb.plots.mpl_decorations.twinx(ax, visible_spine='left')
Create a twin Axes sharing the x-axis.
Parameters
- ax: matplotlib.axes.Axes
Existing Axes
- visible_spine: {‘left’, ‘right’}, str, optional
Position of the only visible axis spine
Returns
- ax_twin: matplotlib.axes.Axes
The newly created Axes instance
See also
matplotlib.axes.Axes.twinx twiny: Create a twin Axes sharing the y-axis.
- rwth_nb.plots.mpl_decorations.twiny(ax, visible_spine='top')
Create a twin Axes sharing the y-axis.
Parameters
- ax: matplotlib.axes.Axes
Existing Axes
- visible_spine: {‘top’, ‘bottom’}, str, optional
Position of the only visible axis spine
Returns
- ax_twin: matplotlib.axes.Axes
The newly created Axes instance
See also
matplotlib.axes.Axes.twiny twinx: Create a twin Axes sharing the x-axis.