uscit module¶
Main module with all of the functions
in principle, we require no extra module
all modules are loaded within the functions
- uscit.save_fig_temp_sys_open(f, delete=True)[source]¶
Saves a Matplotlib figure as a temporary PDF file and opens it using the system’s default program.
- Parameters:
f (matplotlib.figure.Figure) – The figure object to be saved.
delete (bool) – A flag to determine whether the temporary file should be deleted after opening.
- Returns:
A file object representing the temporary PDF file.
- Return type:
tempfile.NamedTemporaryFile
Notes
This function is particularly useful when creating figures for scientific articles and presentations, as it allows you to quickly save and view the figure without having to manually open the file.
Examples
>>> fig, ax = plt.subplots() >>> ax.plot([1, 2, 3], [4, 5, 6]) >>> save_fig_temp_sys_open(fig, delete=False)
- uscit.set_fig_rule(f=None, g=True, delete=True)[source]¶
Function to set rules for matplotlib figures.
It is very useful when trying to figure out margins and locations of access.
- Parameters:
f (matplotlib.figure.Figure, optional) – The figure object to be modified. If not given, the current figure will be used. Default is None.
g (bool, optional) – A flag to turn on/off grid lines. Default is True.
delete (If true, then, the file is deleted automatically. Otherwise you are supposed to do it) –
- Return type:
The path to the temporary file
Examples
Create a sample figure
>>> fig, ax = plt.subplots() >>> ax.plot([1, 2, 3], [4, 5, 6])
Apply the figure rules using the set_fig_rule function
>>> set_fig_rule(f=fig, g=True)
- uscit.set_margin(f=None, x1=None, x2=None, y1=None, y2=None)[source]¶
Adjusts the margins of a matplotlib figure.
parameters are absolute in inches—not a proportion of the figure—.
- Parameters:
f (matplotlib.figure.Figure, optional) – The figure object to be modified. If not given, the current figure will be used. Default is None.
x1 (float, optional) – The fraction of the figure width to reserve as padding for the left side of the plot. Default is None.
x2 (float, optional) – The fraction of the figure width to reserve as padding for the right side of the plot. Default is None.
y1 (float, optional) – The fraction of the figure height to reserve as padding for the bottom of the plot. Default is None.
y2 (float, optional) – The fraction of the figure height to reserve as padding for the top of the plot. Default is None.
- Return type:
None
Example
Create a simple plot and adjust the margins to make room for the legend
>>> x = [1, 2, 3] >>> y = [4, 5, 6] >>> fig, ax = plt.subplots() >>> ax.plot(x, y) >>> set_margin(f=fig, x1=0.1, x2=0.2, y1=0.1, y2=0.2)