|
bitsim
Model, simulate, estimate and control robots in C++
|
Classes | |
| class | Arrow3D |
Functions | |
| list[float] | read_returns (Path path) |
| list[float] | moving_average (list[float] values, int n) |
| None | main (Path directory, Path output) |
| running_mean (x, N=50) | |
| None | plot_vals (Path filename, str title, N=100) |
| plot_values (v) | |
| main (filename) | |
| None | plot_state_values (v, str title) |
| None | plot_rewards (Path filename) |
| main (v_func_filename, avg_score_filename) | |
| rot_mat_2d (angle) | |
| angle_mod (x, zero_2_2pi=False, degree=False) | |
| plot_covariance_ellipse (x, y, cov, chi2=3.0, color="-r", ax=None) | |
| plot_ellipse (x, y, a, b, angle, color="-r", ax=None, **kwargs) | |
| plot_arrow (x, y, yaw, arrow_length=1.0, origin_point_plot_style="xr", head_width=0.1, fc="r", ec="k", **kwargs) | |
| plot_curvature (x_list, y_list, heading_list, curvature, k=0.01, c="-c", label="Curvature") | |
| _arrow3D (ax, x, y, z, dx, dy, dz, *args, **kwargs) | |
| plot_3d_vector_arrow (ax, p1, p2) | |
| plot_triangle (p1, p2, p3, ax) | |
| set_equal_3d_axis (ax, x_lims, y_lims, z_lims) | |
| plot_values (time_vec, values) | |
Variables | |
| N | |
| int | out_dir = Path(sys.argv[1]) if len(sys.argv) > 1 else Path('.') |
| str | SHOW = '--show' in sys.argv |
| list | args = [a for a in sys.argv[1:] if a != '--show'] |
Plot the runs of an experiment that log_experiment wrote. Usage: python plot.py <experiment directory> [output.png] Reads config.json for what was run, and every <run>/episodes.csv, and plots the return of every episode, averaged over 20 episodes, one line per run.
Utility script for plotting with matplotlib
Matplotlib based plotting utilities File edited from: https://github.com/AtsushiSakai/PythonRobotics/blob/master/utils/plot.py
Plot the true and the estimated state that extended_kalman_filter writes to state.csv, and save the plots as x_coordinate.png, y_coordinate.png and orientation.png. Usage: python plot.py [state.csv] [--show]
Plot the speeds and the tow bar force, from the CSV distributed_towing writes. Usage: python plot.py towing.csv distributed_towing.png
Plot x1 over time, from the CSV two_mass_oscillator writes. Usage: python plot.py oscillator.csv two_mass_oscillator.png
|
protected |
Add an 3d arrow to an `Axes3D` instance.
| plot.angle_mod | ( | x, | |
| zero_2_2pi = False, | |||
| degree = False ) |
Angle modulo operation
Default angle modulo range is [-pi, pi)
Parameters
----------
x : float or array_like
A angle or an array of angles. This array is flattened for
the calculation. When an angle is provided, a float angle is returned.
zero_2_2pi : bool, optional
Change angle modulo range to [0, 2pi)
Default is False.
degree : bool, optional
If True, then the given angles are assumed to be in degrees.
Default is False.
Returns
-------
ret : float or ndarray
an angle or an array of modulated angle.
Examples
--------
>>> angle_mod(-4.0)
2.28318531
>>> angle_mod([-4.0])
np.array(2.28318531)
>>> angle_mod([-150.0, 190.0, 350], degree=True)
array([-150., -170., -10.])
>>> angle_mod(-60.0, zero_2_2pi=True, degree=True)
array([300.])
| plot.main | ( | filename | ) |
| None plot.main | ( | Path | directory, |
| Path | output ) |
| plot.main | ( | v_func_filename, | |
| avg_score_filename ) |
| list[float] plot.moving_average | ( | list[float] | values, |
| int | n ) |
| plot.plot_3d_vector_arrow | ( | ax, | |
| p1, | |||
| p2 ) |
| plot.plot_arrow | ( | x, | |
| y, | |||
| yaw, | |||
| arrow_length = 1.0, | |||
| origin_point_plot_style = "xr", | |||
| head_width = 0.1, | |||
| fc = "r", | |||
| ec = "k", | |||
| ** | kwargs ) |
Plot an arrow or arrows based on 2D state (x, y, yaw)
All optional settings of matplotlib.pyplot.arrow can be used.
- matplotlib.pyplot.arrow:
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.arrow.html
Parameters
----------
x : a float or array_like
a value or a list of arrow origin x position.
y : a float or array_like
a value or a list of arrow origin y position.
yaw : a float or array_like
a value or a list of arrow yaw angle (orientation).
arrow_length : a float (optional)
arrow length. default is 1.0
origin_point_plot_style : str (optional)
origin point plot style. If None, not plotting.
head_width : a float (optional)
arrow head width. default is 0.1
fc : string (optional)
face color
ec : string (optional)
edge color
| plot.plot_covariance_ellipse | ( | x, | |
| y, | |||
| cov, | |||
| chi2 = 3.0, | |||
| color = "-r", | |||
| ax = None ) |
This function plots an ellipse that represents a covariance matrix. The ellipse is centered at (x, y) and its shape, size and rotation are determined by the covariance matrix. Parameters: x : (float) The x-coordinate of the center of the ellipse. y : (float) The y-coordinate of the center of the ellipse. cov : (numpy.ndarray) A 2x2 covariance matrix that determines the shape, size, and rotation of the ellipse. chi2 : (float, optional) A scalar value that scales the ellipse size. This value is typically set based on chi-squared distribution quantiles to achieve certain confidence levels (e.g., 3.0 corresponds to ~95% confidence for a 2D Gaussian). Defaults to 3.0. color : (str, optional) The color and line style of the ellipse plot, following matplotlib conventions. Defaults to "-r" (a red solid line). ax : (matplotlib.axes.Axes, optional) The Axes object to draw the ellipse on. If None (default), a new figure and axes are created. Returns: None. This function plots the covariance ellipse on the specified axes.
| plot.plot_curvature | ( | x_list, | |
| y_list, | |||
| heading_list, | |||
| curvature, | |||
| k = 0.01, | |||
| c = "-c", | |||
| label = "Curvature" ) |
Plot curvature on 2D path. This plot is a line from the original path,
the lateral distance from the original path shows curvature magnitude.
Left turning shows right side plot, right turning shows left side plot.
For straight path, the curvature plot will be on the path, because
curvature is 0 on the straight path.
Parameters
----------
x_list : array_like
x position list of the path
y_list : array_like
y position list of the path
heading_list : array_like
heading list of the path
curvature : array_like
curvature list of the path
k : float
curvature scale factor to calculate distance from the original path
c : string
color of the plot
label : string
label of the plot
| plot.plot_ellipse | ( | x, | |
| y, | |||
| a, | |||
| b, | |||
| angle, | |||
| color = "-r", | |||
| ax = None, | |||
| ** | kwargs ) |
This function plots an ellipse based on the given parameters. Parameters ---------- x : (float) The x-coordinate of the center of the ellipse. y : (float) The y-coordinate of the center of the ellipse. a : (float) The length of the semi-major axis of the ellipse. b : (float) The length of the semi-minor axis of the ellipse. angle : (float) The rotation angle of the ellipse, in radians. color : (str, optional) The color and line style of the ellipse plot, following matplotlib conventions. Defaults to "-r" (a red solid line). ax : (matplotlib.axes.Axes, optional) The Axes object to draw the ellipse on. If None (default), a new figure and axes are created. **kwargs: Additional keyword arguments to pass to plt.plot or ax.plot. Returns --------- None. This function plots the ellipse based on the specified parameters.
| None plot.plot_rewards | ( | Path | filename | ) |
| None plot.plot_state_values | ( | v, | |
| str | title ) |
| plot.plot_triangle | ( | p1, | |
| p2, | |||
| p3, | |||
| ax ) |
| None plot.plot_vals | ( | Path | filename, |
| str | title, | ||
| N = 100 ) |
| plot.plot_values | ( | time_vec, | |
| values ) |
| plot.plot_values | ( | v | ) |
| list[float] plot.read_returns | ( | Path | path | ) |
| plot.rot_mat_2d | ( | angle | ) |
Create 2D rotation matrix from an angle Parameters ---------- angle : Returns ------- A 2D rotation matrix Examples -------- >>> angle_mod(-4.0)
| plot.running_mean | ( | x, | |
| N = 50 ) |
| plot.set_equal_3d_axis | ( | ax, | |
| x_lims, | |||
| y_lims, | |||
| z_lims ) |
Helper function to set equal axis
Args:
ax (Axes3DSubplot): matplotlib 3D axis, created by
`ax = fig.add_subplot(projection='3d')`
x_lims (np.array): array containing min and max value of x
y_lims (np.array): array containing min and max value of y
z_lims (np.array): array containing min and max value of z
| list plot.args = [a for a in sys.argv[1:] if a != '--show'] |
| plot.N |
| int plot.out_dir = Path(sys.argv[1]) if len(sys.argv) > 1 else Path('.') |
| str plot.SHOW = '--show' in sys.argv |