plotting module
- plotting.calculate_odr_line_equation2(x, y, ax)[source]
Calculate the ODR (Orthogonal Distance Regression) line equation and plot it.
This function performs an ODR regression on the given data and plots the resulting regression line on the specified axis. It also writes the equation of the regression line in the top left corner of the plot.
- Parameters:
x (numpy.ndarray) – Array of x-values.
y (numpy.ndarray) – Array of y-values.
ax (matplotlib.axes.Axes) – The axis on which to plot the regression line.
Examples
>>> x = np.random.rand(20) >>> y = 2 * x + np.random.rand(20) >>> fig, ax = plt.subplots() >>> ax.scatter(x, y, label='Data') >>> calculate_odr_line_equation2(x, y, ax) >>> ax.legend() >>> plt.show()
Notes
This function filters out data points where x < 1.5 before performing the ODR regression.
- plotting.draw_file_tree(master_path, include_files=False, suppress_pycache=False, suppress_hidden=False)[source]
Draw a file tree diagram for the specified master directory.
- Parameters:
master_path (str) – The path to the master directory.
include_files (bool, optional) – Include files in the file tree if True, otherwise only include directories. Defaults to False.
suppress_pycache (bool, optional) – Suppress the ‘__pycache__’ directory if True. Defaults to False.
suppress_hidden (bool, optional) – Suppress hidden files and directories if True. Defaults to False.
- plotting.plot_geographic_locations(lon, lat, color, projection='Mollweide', title='Geographic Locations', third_field_label='Third Field', colorbar_range=None, **kwargs)[source]
Plot geographic locations on a map with color-coded points.
This function generates a map projection specified by ‘projection’ (default is Mollweide) and plots geographic locations defined by longitude (‘lon’) and latitude (‘lat’). The color of the points is determined by the ‘color’ parameter, and an optional third field can be labeled on the colorbar. You can customize the color range using ‘colorbar_range’.
- Parameters:
lon (array-like) – Array of longitudes for the locations.
lat (array-like) – Array of latitudes for the locations.
color (array-like) – Array of values determining the color of each point.
projection (str, optional) – Map projection type. Default is ‘Mollweide’.
title (str, optional) – Title for the plot. Default is ‘Geographic Locations’.
third_field_label (str, optional) – Label for the third field on the colorbar.
colorbar_range (list, optional) – Custom color range for the colorbar. Default is determined by the data.
**kwargs – Additional keyword arguments to pass to the scatter plot.
Examples
>>> lon = [0, 90, 180, -90] >>> lat = [0, 30, 60, -30] >>> color = [10, 20, 30, 40] >>> plot_geographic_locations(lon, lat, color, ... projection='PlateCarree', ... title='Sample Locations', ... third_field_label='Value', ... colorbar_range=[0, 50], s=100, ... cmap='coolwarm')
- plotting.plot_panels(data, plot_type='scatter', cmap='YlGnBu', titles=None, xlabels=None, ylabels=None, z_values=None, figure_scale=1.0, save_path=None)[source]
Plot multiple panels with customizable settings, each with data series in different colors and a legend.
- Parameters:
data (list of lists) – A list where each element represents a separate plot. Each element is a list of dictionaries, where each dictionary represents a data series and contains ‘x’, ‘y’, and ‘label’ values. Multiple data series for a plot should be passed as separate dictionaries within the nested list.
plot_type (str, optional) – Type of plot to create (‘scatter’ or ‘line’). Default is ‘scatter’.
cmap (str, optional) – Color map for scatter plot. Default is ‘YlGnBu’.
titles (list or None, optional) – Titles for each panel. Can be a list of strings or None to omit titles.
xlabels (list or None, optional) – X-axis labels for each panel. Can be a list of strings or None to omit x-axis labels.
ylabels (list or None, optional) – Y-axis labels for each panel. Can be a list of strings or None to omit y-axis labels.
z_values (None or list, optional) – Z-values for color mapping in scatter plot. Can be None or a list of values.
figure_scale (float, optional) – Scale factor for the figure size. Default is 1.0.
save_path (str or None, optional) – File path to save the plot as an image. None to display the plot without saving.
- Return type:
None
Examples
>>> data = [ ... [ ... {'x': [1, 2, 3], 'y': [2, 3, 1], 'label': 'Dataset 1'}, ... {'x': [1, 2, 3], 'y': [1, 1, 2], 'label': 'Dataset 2'} ... ], ... [ ... {'x': [4, 5, 6], 'y': [3, 4, 4], 'label': 'Dataset 3'} ... ] ... ] >>> titles = ['Panel 1', 'Panel 2'] >>> xlabels = ['X Label 1', 'X Label 2'] >>> ylabels = ['Y Label 1', 'Y Label 2'] >>> z_values = [1, 2] # For color mapping in scatter plot >>> plot_panels(data, plot_type='scatter', cmap='viridis', titles=titles, ... xlabels=xlabels, ylabels=ylabels, z_values=z_values, ... figure_scale=1.2, save_path='plot.png')
- plotting.plot_three_scatter(data1, data2, data3, labels=None, x_labels=None, y_labels=None)[source]
Plot three scatter plots with regression lines and custom labels.
- Parameters:
data1 (numpy.ndarray) – Data for the first scatter plot as a 2D array (x, y).
data2 (numpy.ndarray) – Data for the second scatter plot as a 2D array (x, y).
data3 (numpy.ndarray) – Data for the third scatter plot as a 2D array (x, y).
labels (list, optional) – List of labels for each plot. Default is [None, None, None].
x_labels (list, optional) – List of x-axis labels for each plot. Default is [None, None, None].
y_labels (list, optional) – List of y-axis labels for each plot. Default is [None, None, None].
Examples
>>> x1 = np.random.rand(20) >>> y1 = 2 * x1 + np.random.rand(20) >>> data1 = np.column_stack((x1, y1))
>>> x2 = np.random.rand(20) >>> y2 = 3 * x2 + np.random.rand(20) >>> data2 = np.column_stack((x2, y2))
>>> x3 = np.random.rand(20) >>> y3 = 4 * x3 + np.random.rand(20) >>> data3 = np.column_stack((x3, y3))
>>> labels = ['Plot 1', 'Plot 2', 'Plot 3'] >>> x_labels = ['X Label 1', 'X Label 2', 'X Label 3'] >>> y_labels = ['Y Label 1', 'Y Label 2', 'Y Label 3']
>>> plot_three_scatter(data1, data2, data3, labels, x_labels, y_labels)