idstools.view.common¶
Module Contents¶
- class idstools.view.common.BasePlot[source]¶
- database_info(ax, title, hostdir, shot, run, t)[source]¶
Add database and shot information as text annotation to a plot axes.
Displays metadata (host directory, shot number, run number, and time) as text on the right side of the plot axis. Useful for tracking the source and time point of plotted data.
Examples
>>> ax = plt.gca() >>> plot = BasePlot() >>> plot.database_info(ax, "Plasma Profile", "mdsplus", 134174, 1, 0.5)
-
class idstools.view.common.PlotCanvas(nrows=
1, ncols=1, *args, **kwargs)[source]¶ - fig¶
-
ncols =
'1'¶
-
nrows =
'1'¶
-
add_axes(title=
None, xlabel=None, ylabel=None, row=0, col=0, rowspan=1, colspan=1, **kwargs)[source]¶ Add a new subplot axes to the figure at a specified grid position.
Creates a subplot at the given row/column location with optional spanning across multiple grid cells. Automatically sets title and axis labels if provided.
- Parameters:¶
- title=
None¶ Title for the axes. Defaults to None.
- xlabel=
None¶ Label for the x-axis. Defaults to None.
- ylabel=
None¶ Label for the y-axis. Defaults to None.
- row=
0¶ Row index in the grid (0-indexed). Defaults to 0.
- col=
0¶ Column index in the grid (0-indexed). Defaults to 0.
- rowspan=
1¶ Number of rows this axes spans. Defaults to 1.
- colspan=
1¶ Number of columns this axes spans. Defaults to 1.
- **kwargs¶
Additional keyword arguments passed to plt.subplot2grid().
- title=
- Returns:¶
The created axes object for plotting.
- Return type:¶
Examples
>>> canvas = PlotCanvas(nrows=2, ncols=2) >>> ax = canvas.add_axes(title="Main Plot", xlabel="X", ylabel="Y", row=0, col=0) >>> ax.plot([1, 2, 3], [1, 4, 9])
- get_current_fig_manager()[source]¶
Get the current matplotlib figure manager.
Returns the matplotlib figure manager for the active figure, which can be used to interact with the figure window and backend.
Examples
>>> canvas = PlotCanvas() >>> fig_mgr = canvas.get_current_fig_manager() >>> # Can access window properties, etc.
- static is_axes_empty(ax)[source]¶
Check if a given Matplotlib Axes object is empty.
An Axes object is considered empty if it has no data, no lines, no patches, and no texts.
Parameters: ax (matplotlib.axes.Axes): The Axes object to check.
Returns: bool: True if the Axes object is empty, False otherwise.
- remove_empty_axes()[source]¶
Remove empty axes from the figure.
This method iterates over all axes in the figure and removes those that are empty. An axis is considered empty if the PlotCanvas.is_axes_empty method returns True.
- Returns:¶
None
-
save(fname, width=
11.69, height=8.27, dpi='figure')[source]¶ Save the current matplotlib figure to a file.
Saves the figure with specified dimensions and resolution. Supports all matplotlib-compatible file formats (PDF, PNG, SVG, etc.) based on file extension.
- Parameters:¶
- fname¶
Output filename (e.g., ‘figure.pdf’, ‘plot.png’). The file extension determines the format.
- width=
11.69¶ Figure width in inches. Defaults to 11.69 (A4 width).
- height=
8.27¶ Figure height in inches. Defaults to 8.27 (A4 height).
- dpi=
'figure'¶ Resolution in dots per inch. If ‘figure’, uses the default figure DPI. Defaults to ‘figure’.
- Returns:¶
None
Examples
>>> canvas = PlotCanvas() >>> ax = canvas.add_axes() >>> ax.plot([1, 2, 3], [1, 2, 3]) >>> canvas.save('my_plot.pdf') # Save as PDF >>> canvas.save('my_plot.png', dpi=300) # Save as PNG with high resolution
-
set_style(style=
'default')[source]¶ The function setStyle in allows you to set different color schemes for plots using Matplotlib based on the specified style parameter. Available styles are vibrant, retro, muted, high-vis, contrast, bright
-
set_sup_title(text=
'', *args, **kwargs)[source]¶ Set the super-title (title spanning all subplots) for the figure.
Examples
>>> canvas = PlotCanvas(nrows=2, ncols=2) >>> canvas.set_sup_title("Main Figure Title", fontsize=16, fontweight='bold')
-
set_text(x=
0.001, y=0.985, text='', ha='left', fontsize=7)[source]¶ Add text annotation to the figure at a specific position.
Places text at figure coordinates (independent of axes), useful for adding annotations, credits, or metadata to the entire figure.
- Parameters:¶
- x=
0.001¶ X-coordinate in figure coordinates (0=left, 1=right). Defaults to 0.001 (near left edge).
- y=
0.985¶ Y-coordinate in figure coordinates (0=bottom, 1=top). Defaults to 0.985 (near top).
- text=
''¶ Text string to display. Defaults to empty string.
- ha=
'left'¶ Horizontal alignment (‘left’, ‘center’, ‘right’). Defaults to ‘left’.
- fontsize=
7¶ Font size in points. Defaults to 7.
- x=
- Returns:¶
None
Examples
>>> canvas = PlotCanvas() >>> canvas.set_text(x=0.5, y=0.95, text="Main Title", ha="center", fontsize=14)
- show(*args, **kwargs)[source]¶
Display the figure in a window and maximize it if possible.
Attempts to maximize the figure window and show it. If window resizing is not supported by the current matplotlib backend, the figure is displayed normally.
Notes
Uses the TkAgg backend for window resizing when available. Other backends (agg, Qt) may not support window maximization.
Examples
>>> canvas = PlotCanvas() >>> ax = canvas.add_axes() >>> ax.plot([1, 2, 3], [1, 4, 9]) >>> canvas.show()
- class idstools.view.common.Terminal[source]¶
-
LINE =
"'--------'"¶
-
TAB =
"' '"¶
-
tabsize =
'10'¶
-
print(text, style=
None, panel=False, pretty=False)[source]¶ Print formatted text to the console with optional styling.
Prints text with optional Rich library formatting and styling. If Rich is available, supports styled output, panels, and pretty-printing. Falls back to standard print if Rich is not installed.
- Parameters:¶
- text¶
Text string to print, or dictionary to pretty-print.
- style=
None¶ Rich text styling (e.g., ‘green’, ‘bold red’). Defaults to ‘green’ if Rich is available.
- panel=
False¶ If True, text is displayed in a Rich panel box. Ignored if Rich is unavailable. Defaults to False.
- pretty=
False¶ If True, uses Rich Pretty formatting for better display of complex objects. Ignored if Rich is unavailable. Defaults to False.
- Returns:¶
None
Notes
Dictionaries are automatically pretty-printed regardless of other options
Requires ‘rich’ package for advanced formatting. Falls back to standard print.
Set style=None to disable coloring with Rich.
Examples
>>> terminal = Terminal() >>> terminal.print("Hello World", style="green") >>> terminal.print({"data": [1, 2, 3]}) # Pretty prints dict >>> terminal.print("Warning!", style="bold red", panel=True)
-
LINE =
-
idstools.view.common.current_directory =
"b'.'"¶
- idstools.view.common.logger¶
- idstools.view.common.mplstyle_filepath¶
-
idstools.view.common.rich_available =
'True'¶