Skip to content

Commit

Permalink
Define custom pymatviz plotly templates (#110)
Browse files Browse the repository at this point in the history
* merge pymatviz/plot_defaults.py into pymatviz/__init__.py

* define custom plotly templates pymatviz_white+pymatviz_black

* bump GHA action versions
  • Loading branch information
janosh committed Dec 10, 2023
1 parent ead0ce9 commit fddff16
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/link-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run markdown link check
uses: gaurav-nelson/github-action-markdown-link-check@v1
4 changes: 2 additions & 2 deletions .github/workflows/svgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up node
uses: actions/setup-node@v3
uses: actions/setup-node@v4

- name: Install SVGO
run: npm install --global svgo
Expand Down
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ repos:
hooks:
- id: ruff
args: [--fix]
types_or: [python, jupyter]
- id: ruff-format
types_or: [python, jupyter]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
Expand Down
2 changes: 1 addition & 1 deletion dataset_exploration/boltztrap_mp/explore_boltztrap_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@


# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset

from pymatviz import ptable_heatmap
from pymatviz.plot_defaults import plt


# %%
Expand Down
2 changes: 1 addition & 1 deletion dataset_exploration/camd_2022/explore_camd_2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
# %%
import os

import matplotlib.pyplot as plt
import pandas as pd
import requests
from pymatgen.symmetry.groups import SpaceGroup

from pymatviz import annotate_bars, count_elements, ptable_heatmap, spacegroup_sunburst
from pymatviz.plot_defaults import plt


# %% Download data (if needed)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# %%
import matplotlib.pyplot as plt
import plotly.express as px
from aviary.wren.utils import count_wyckoff_positions, get_aflow_label_from_spglib
from matminer.datasets import load_dataset
from tqdm import tqdm

from pymatviz import (
crystal_sys_order,
ptable_heatmap,
ptable_heatmap_plotly,
spacegroup_hist,
spacegroup_sunburst,
)
from pymatviz.plot_defaults import crystal_sys_order, plt, px
from pymatviz.utils import crystal_sys_from_spg_num


Expand Down
3 changes: 2 additions & 1 deletion dataset_exploration/matbench/expt_gap/explore_expt_gap.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# %%
from __future__ import annotations

import matplotlib.pyplot as plt
import plotly.express as px
from matminer.datasets import load_dataset
from pymatgen.core import Composition

from pymatviz import ptable_heatmap
from pymatviz.plot_defaults import plt, px


"""Stats for the matbench_expt_gap dataset.
Expand Down
2 changes: 1 addition & 1 deletion dataset_exploration/matbench/jdft2d/explore_jdft2d.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset
from tqdm import tqdm

from pymatviz import ptable_heatmap, spacegroup_hist, spacegroup_sunburst
from pymatviz.plot_defaults import plt


"""Stats for the matbench_jdft2d dataset.
Expand Down
10 changes: 8 additions & 2 deletions dataset_exploration/matbench/log_g+kvrh/explore_log_g+krvh.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
# %%
from time import perf_counter

import matplotlib.pyplot as plt
import numpy as np
import plotly.express as px
from aviary.wren.utils import count_wyckoff_positions, get_aflow_label_from_spglib
from matminer.datasets import load_dataset
from pymatgen.core import Structure
from tqdm import tqdm

from pymatviz import ptable_heatmap, spacegroup_hist, spacegroup_sunburst
from pymatviz.plot_defaults import crystal_sys_order, plt, px
from pymatviz import (
crystal_sys_order,
ptable_heatmap,
spacegroup_hist,
spacegroup_sunburst,
)
from pymatviz.utils import crystal_sys_from_spg_num


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset

from pymatviz import ptable_heatmap
from pymatviz.plot_defaults import plt


"""Stats for the matbench_mp_e_form dataset.
Expand Down
2 changes: 1 addition & 1 deletion dataset_exploration/matbench/mp_gap/explore_mp_gap.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset

from pymatviz import ptable_heatmap
from pymatviz.plot_defaults import plt


"""Stats for the matbench_mp_gap dataset.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset
from tqdm import tqdm

Expand All @@ -8,7 +9,6 @@
ptable_heatmap,
spacegroup_sunburst,
)
from pymatviz.plot_defaults import plt
from pymatviz.utils import crystal_sys_from_spg_num


Expand Down
2 changes: 1 addition & 1 deletion dataset_exploration/matbench/phonons/explore_phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@


# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset
from tqdm import tqdm

from pymatviz import ptable_heatmap, spacegroup_hist
from pymatviz.plot_defaults import plt


# %%
Expand Down
2 changes: 1 addition & 1 deletion dataset_exploration/matbench/steels/explore_steels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@


# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset

from pymatviz import ptable_heatmap
from pymatviz.plot_defaults import plt


# %%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@


# %%
import matplotlib.pyplot as plt
from matminer.datasets import load_dataset
from tqdm import tqdm

from pymatviz import ptable_heatmap, spacegroup_hist
from pymatviz.plot_defaults import plt


# %%
Expand Down
4 changes: 2 additions & 2 deletions dataset_exploration/wbm/explore_wbm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# %%
import pandas as pd
import plotly.express as px

from pymatviz import ptable_heatmap_plotly, spacegroup_sunburst
from pymatviz.plot_defaults import crystal_sys_order, px
from pymatviz import crystal_sys_order, ptable_heatmap_plotly, spacegroup_sunburst
from pymatviz.utils import crystal_sys_from_spg_num


Expand Down
6 changes: 4 additions & 2 deletions examples/matbench_dielectric_eda.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Matbench Dielectric Dataset\n",
"\n",
"Exploratory Data Analysis (EDA). [MPContribs link](https://ml.materialsproject.org/projects/matbench_dielectric)"
"Exploratory Data Analysis (EDA). [MPContribs link](https://ml.materialsproject.org/projects/matbench_dielectric)\n"
]
},
{
Expand All @@ -26,11 +26,13 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import plotly.express as px\n",
"import plotly.io as pio\n",
"from matminer.datasets import load_dataset\n",
"from tqdm import tqdm\n",
"\n",
"from pymatviz import ptable_heatmap, spacegroup_hist, spacegroup_sunburst\n",
"from pymatviz.plot_defaults import pio, plt, px\n",
"from pymatviz.utils import get_crystal_sys\n",
"\n",
"\n",
Expand Down
1 change: 0 additions & 1 deletion examples/mp_bimodal_e_form.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"__author__ = \"Janosh Riebesell\"\n",
"__date__ = \"2022-08-11\"\n",
"\n",
"pio.templates.default = \"plotly_white\"\n",
"pio.renderers.default = \"png\""
]
},
Expand Down
21 changes: 10 additions & 11 deletions examples/mprester_ptable.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"outputs": [],
"source": [
"# dash needed for interactive plots\n",
"!pip install pymatviz dash\n"
"!pip install pymatviz dash"
]
},
{
Expand All @@ -38,12 +38,11 @@
"__date__ = \"2022-07-21\"\n",
"\n",
"\n",
"pio.templates.default = \"plotly_white\"\n",
"# Interactive plotly figures don't show up on GitHub.\n",
"# https://github.com/plotly/plotly.py/issues/931\n",
"# change renderer from \"svg\" to \"notebook\" to get hover tooltips back\n",
"# (but blank plots on GitHub!)\n",
"pio.renderers.default = \"png\"\n"
"pio.renderers.default = \"png\""
]
},
{
Expand All @@ -60,7 +59,7 @@
}
],
"source": [
"print(\", \".join(MPRester().materials.summary.available_fields))\n"
"print(\", \".join(MPRester().materials.summary.available_fields))"
]
},
{
Expand All @@ -75,7 +74,7 @@
" mp_data = mpr.materials.summary.search(\n",
" # nelements=[4, None], # 4 or less elements\n",
" fields=[\"material_id\", \"formula\", \"nelements\"]\n",
" )\n"
" )"
]
},
{
Expand All @@ -85,7 +84,7 @@
"outputs": [],
"source": [
"df_mp = pd.DataFrame(map(dict, mp_data)).set_index(\"material_id\")\n",
"df_mp.head()\n"
"df_mp.head()"
]
},
{
Expand All @@ -106,7 +105,7 @@
"# %store df_mp\n",
"\n",
"# uncomment line to load cached MP data from disk\n",
"%store -r df_mp\n"
"%store -r df_mp"
]
},
{
Expand All @@ -123,7 +122,7 @@
"compound_counts_by_arity = {\n",
" key: (df_mp.nelements == idx).sum()\n",
" for idx, key in enumerate(elem_counts_by_arity, 1)\n",
"}\n"
"}"
]
},
{
Expand Down Expand Up @@ -188,7 +187,7 @@
" f\"Element distribution of {n_compounds:,} {arity_label} compounds in \"\n",
" \"Materials Project\",\n",
" fontsize=16,\n",
" )\n"
" )"
]
},
{
Expand All @@ -212,7 +211,7 @@
" )\n",
" fig.update_layout(title=dict(text=title, x=0.45, y=0.93))\n",
" arity_figs[arity_label] = fig\n",
" # fig.show() # uncomment to show plotly figures\n"
" # fig.show() # uncomment to show plotly figures"
]
},
{
Expand Down Expand Up @@ -266,7 +265,7 @@
" return arity_figs[dropdown_value]\n",
"\n",
"\n",
"app.run(debug=True, mode=\"inline\")\n"
"app.run(debug=True, mode=\"inline\")"
]
}
],
Expand Down
Loading

0 comments on commit fddff16

Please sign in to comment.