Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor format tweaks #120

Merged
merged 41 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
dfd031e
minor format tweaks
DanielYang59 Jan 9, 2024
f24e9f2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 9, 2024
3e4d0e5
minor tweak
DanielYang59 Jan 9, 2024
afafb94
Merge branch 'heatmap' of https://github.com/DanielYang59/pymatviz in…
DanielYang59 Jan 9, 2024
08841e6
add heatmap plotter
DanielYang59 Jan 11, 2024
1ec14c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 11, 2024
0c539bc
reverse default import weasyprint
DanielYang59 Jan 11, 2024
028a639
Merge branch 'heatmap' of https://github.com/DanielYang59/pymatviz in…
DanielYang59 Jan 11, 2024
6f28995
enforce strict spg type check
DanielYang59 Jan 11, 2024
ccac93c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 11, 2024
dffa4d1
reverse weasyprint deletion
DanielYang59 Jan 11, 2024
4b40498
Merge branch 'heatmap' of https://github.com/DanielYang59/pymatviz in…
DanielYang59 Jan 11, 2024
13e1194
add colormap truncate method
DanielYang59 Jan 16, 2024
3e77eda
add combine colormap and unit tests
DanielYang59 Jan 16, 2024
3119644
revise docstring
DanielYang59 Jan 16, 2024
fee6850
add unit test for cmap truncate
DanielYang59 Jan 16, 2024
ec2773d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 16, 2024
62cb97e
add heatmap unit test
DanielYang59 Jan 16, 2024
1114850
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 16, 2024
b30ea2d
add test for truncate exceptions
DanielYang59 Jan 16, 2024
b0cce0b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 16, 2024
f28f0fb
tweak format
DanielYang59 Jan 19, 2024
ba8fdc3
Merge branch 'heatmap' of https://github.com/DanielYang59/pymatviz in…
DanielYang59 Jan 19, 2024
93e691d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 19, 2024
b3b128c
minor cleanup
DanielYang59 Jan 22, 2024
4caf95b
add heatmap example
DanielYang59 Jan 22, 2024
cda260c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 22, 2024
c6dfaf1
fix some ruff errors
janosh Jan 22, 2024
7355f72
drop custom truncate func
DanielYang59 Jan 29, 2024
1cf1d19
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 29, 2024
84a4bb4
stress the use of node in cmap
DanielYang59 Jan 29, 2024
1500748
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 29, 2024
fccf532
remove colormap and heatmap
DanielYang59 Feb 2, 2024
1450ec6
remove heatmap
DanielYang59 Feb 2, 2024
ca08b5e
bump ruff to 0.2.0
janosh Feb 2, 2024
fe21283
revert readme
janosh Feb 2, 2024
1b8c6ec
get mpl_key, plotly_key from type Backend, used in pretty_metric_label
janosh Feb 2, 2024
a349883
delete mixing-enthalpy.csv.gz
janosh Feb 2, 2024
f3e7ca4
Merge branch 'main' into pr/DanielYang59/120-1
janosh Feb 2, 2024
6f97321
fix TypeError: Expect integer for space group number, got str
janosh Feb 2, 2024
3688713
fix type checking in crystal_sys_from_spg_num
janosh Feb 2, 2024
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
13 changes: 6 additions & 7 deletions pymatviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,14 @@
# use pio.kaleido.scope.mathjax = None


"""
Importing this module has side-effects that apply sensible (often, not always) global
defaults settings for plotly and matplotlib like increasing font size, prettier
axis labels (plotly only) and higher figure resolution (matplotlib only).
# Importing this module has side-effects that apply sensible (often, not always) global
# defaults settings for plotly and matplotlib like increasing font size, prettier
# axis labels (plotly only) and higher figure resolution (matplotlib only).

To use it, simply import this module before generating any plots:
# To use it, simply import this module before generating any plots:

# import pymatviz

import pymatviz
"""

plt.rc("font", size=16)
plt.rc("savefig", bbox="tight", dpi=200)
Expand Down
2 changes: 1 addition & 1 deletion pymatviz/histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def spacegroup_hist(
for crys_sys, count, width, color in crys_sys_counts.itertuples():
x1 = x0 + width

for patch in ax.patches[0 if x0 == 1 else x0 : x1 + 1]:
for patch in ax.patches[0 if x0 == 1 else x0: x1 + 1]:
patch.set_facecolor(color)

text_kwds = dict(transform=trans, horizontalalignment="center") | (
Expand Down
15 changes: 5 additions & 10 deletions pymatviz/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import matplotlib.pyplot as plt
import plotly.graph_objects as go
from tqdm import tqdm
from weasyprint import HTML


if TYPE_CHECKING:
Expand Down Expand Up @@ -109,13 +110,13 @@ def save_fig(
if path.lower().endswith(".svelte"):
# insert {...$$props} into top-level div to be able to post-process and
# style plotly figures from within Svelte files
with open(path) as file:
with open(path, encoding="utf-8") as file:
text = file.read().replace("<div>", "<div {...$$props}>", 1)
with open(path, "w") as file:
with open(path, "w", encoding="utf-8") as file:
# add trailing newline for pre-commit end-of-file commit hook
file.write(text + "\n")
if style:
with open(path, "r+") as file:
with open(path, "r+", encoding="utf-8") as file:
# replace first '<div ' with '<div {style=} '
file.write(file.read().replace("<div ", f"<div {style=} ", 1))
else:
Expand Down Expand Up @@ -203,12 +204,6 @@ def df_to_pdf(
values CSS strings. Example: dict("td, th": "border: none; padding: 4px;")
**kwargs: Keyword arguments passed to Styler.to_html().
"""
try:
from weasyprint import HTML
except ImportError as exc:
msg = "weasyprint not installed\nrun pip install weasyprint"
raise ImportError(msg) from exc

if styler_css:
styler_css = styler_css if isinstance(styler_css, dict) else DEFAULT_DF_STYLES
styler.set_table_styles(
Expand Down Expand Up @@ -354,7 +349,7 @@ def df_to_html_table(
if styles is not None:
# insert styles at end of closing </style> tag so they override default styles
html = html.replace("</style>", f"{styles}\n</style>")
with open(file_path, "w") as file:
with open(file_path, "w", encoding="utf-8") as file:
file.write(html)


Expand Down
6 changes: 3 additions & 3 deletions pymatviz/phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ def plot_phonon_bands(
f"Only {PhononBands.__name__} objects supported, got {type_name}"
)
branches = {pretty_sym_point(branch["name"]) for branch in bs.branches}
if not common_branches:
common_branches = branches
else:
if common_branches:
common_branches = common_branches & branches
else:
common_branches = branches

if not common_branches:
raise ValueError("No common branches found among the band structures.")
Expand Down
4 changes: 1 addition & 3 deletions pymatviz/uncertainty.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ def get_std_decay(y_true: ArrayLike, y_pred: ArrayLike, y_std: ArrayLike) -> Arr
# increasing count of the number of samples in each element of cumsum()
n_inc = range(1, len(abs_err) + 1)

decay_by_std = abs_err[y_std_sort].cumsum() / n_inc

return decay_by_std # noqa: RET504
return abs_err[y_std_sort].cumsum() / n_inc # noqa: RET504


def error_decay_with_uncert(
Expand Down
19 changes: 10 additions & 9 deletions pymatviz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,24 @@ def annotate_metrics(

def crystal_sys_from_spg_num(spg: int) -> CrystalSystem:
"""Get the crystal system for an international space group number."""
# not using isinstance(n, int) to allow 0-decimal floats
if not (spg == int(spg) and 0 < spg < 231):
spg = int(spg)
if not 1 <= spg <= 230:
raise ValueError(f"Invalid space group {spg}")

if 0 < spg < 3:
if 1 <= spg <= 2:
return "triclinic"
if spg < 16:
elif spg <= 15:
return "monoclinic"
if spg < 75:
elif spg <= 74:
return "orthorhombic"
if spg < 143:
elif spg <= 142:
return "tetragonal"
if spg < 168:
elif spg <= 167:
return "trigonal"
if spg < 195:
elif spg <= 194:
return "hexagonal"
return "cubic"
else:
return "cubic"


def add_identity_line(
Expand Down