Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cdiutils/examples/analyze_bcdi_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
" \"reconstruction_file\": \"mode.h5\"\n",
"}\n",
"\n",
"# You choose, either you specify it in the metadata, or you want\n",
"# the dump_dir to be dependent on the 'sample_name' and 'scan' or other\n",
"# things.\n",
"# Required, you choose, either you specify it in the metadata, or you\n",
"# want the dump_dir to be dependent on the 'sample_name' and 'scan' or\n",
"# other things.\n",
"metadata[\"dump_dir\"] = (\n",
" os.getcwd() + f'/results/{metadata[\"sample_name\"]}/S{metadata[\"scan\"]}/'\n",
")\n",
Expand Down Expand Up @@ -106,7 +106,7 @@
"usetex = True # might not work if running the notebook directly on nice or slurm\n",
"show = True\n",
"verbose = True\n",
"debug = True\n",
"debug = False\n",
"\n",
"# PyNX parameters\n",
"\n",
Expand Down Expand Up @@ -326,7 +326,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.10.0"
},
"vscode": {
"interpreter": {
Expand Down
69 changes: 57 additions & 12 deletions cdiutils/plot/formatting.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,52 @@
from typing import Union

import colorcet
import matplotlib
import matplotlib.ticker as mticker
import numpy as np
import colorcet


CXI_VIEW_PARAMETERS = {
"z+": {"axis": 0, "plane_axes": [2, 1], "yaxis_points_left": True},
"z-": {"axis": 0, "plane_axes": [2, 1], "yaxis_points_left": False},
"y+": {"axis": 1, "plane_axes": [2, 0], "yaxis_points_left": False},
"y-": {"axis": 1, "plane_axes": [2, 0], "yaxis_points_left": True},
"x+": {"axis": 2, "plane_axes": [0, 1], "yaxis_points_left": False},
"x-": {"axis": 2, "plane_axes": [0, 1], "yaxis_points_left": True},
}


def get_extents(
shape: tuple,
voxel_size: tuple | list | np.ndarray,
plane: list,
zero_centered: bool = True,
) -> tuple:
"""Find the extents for matshow/imshow plotting, for a given plane.

Args:
shape (tuple): the shape of the data to plot.
voxel_size (tuple | list | np.ndarray): the voxel size of
the data to plot.
voxel_size (tuple | list | np.ndarray): the voxel size of
the data to plot.
plane (list): what plane to get the extents from. Should be a
list of 2 axis integers.
zero_centered (bool, optional): whether the plot must be
centered at zero. Defaults to True.

Returns:
tuple: first two values correspond to x-axis extent, last two
to the y-axis extent in the matshow/imshow plot.
"""
absolute_extents = [
voxel_size[i] * shape[i] // (2 if zero_centered else 1)
for i in range(3)
]
return (
-absolute_extents[plane[0]] if zero_centered else 0,
absolute_extents[plane[0]],
-absolute_extents[plane[1]] if zero_centered else 0,
absolute_extents[plane[1]],
)


def set_plot_configs():
Expand Down Expand Up @@ -84,12 +127,12 @@ def set_plot_configs():
def update_plot_params(
style: str = "default",
usetex: bool = True,
use_siunitx: bool = False,
use_siunitx: bool = True,
**kwargs
) -> None:
"""Update the matplotlib plot parameters to plublication style"""

if style in ("default", "nature", "NATURE"):
if style in ("default", "nature"):
parameters = {
"lines.linewidth": 1,
"lines.markersize": 1,
Expand Down Expand Up @@ -118,7 +161,7 @@ def update_plot_params(
**parameters
)
if use_siunitx:
usetex = True
# bypass usetex value, usetex will be set to True
matplotlib.pyplot.rcParams.update(
**{
'text.latex.preamble': (
Expand All @@ -128,17 +171,19 @@ def update_plot_params(
+ (
r'\usepackage{sansmath} \sansmath'
r'\usepackage{textgreek}'
if style == "nature" else r'\usepackage{amsmath}'
if style in ("default", "nature")
else r'\usepackage{amsmath}'
)
)
),
"text.usetex": True
}
)

if usetex:
if usetex and not use_siunitx:
matplotlib.pyplot.rcParams.update(
**{
"mathtext.default": "regular",
"text.usetex": usetex,
"text.usetex": True,
"font.family": "sans-serif",
"font.sans-serif": ["Liberation Sans"]
}
Expand All @@ -162,7 +207,7 @@ def get_figure_size(
"""
Get the figure dimensions to avoid scaling in LaTex.

This function was copied from
This function was taken from
https://jwalton.info/Embed-Publication-Matplotlib-Latex/

:param width: Document width in points, or string of predefined
Expand All @@ -174,7 +219,7 @@ def get_figure_size(
:return: dimensions of the figure in inches (tuple)
"""
if width == 'default':
width_pt = 390
width_pt = 420
elif width == 'thesis':
width_pt = 455.30101
elif width == 'beamer':
Expand Down
Loading