Skip to content

Commit

Permalink
- Introduced new plot_utils.py with Wes Anderson color palettes and u…
Browse files Browse the repository at this point in the history
…tility functions

- Updated Fermi surface 2D configuration to use default color map
- Modified import statements in scriptFermi2D.py
- Adjusted default colormap in fermi_surface_2d.yml
  • Loading branch information
Logan L Lang committed Mar 1, 2025
1 parent 3ec13c5 commit cf696d9
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 9 deletions.
4 changes: 3 additions & 1 deletion pyprocar/cfg/fermi_surface_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from pyprocar.cfg.base import PlotType, BaseConfig

from pyprocar.utils.plot_utils import DEFAULT_COLORS, wes_anderson_palettes, create_colormap


class FermiSurface2DMode(Enum):
"""
Expand Down Expand Up @@ -103,7 +105,7 @@ class FermiSurface2DConfig(BaseConfig):
plot_color_bar: bool = False

# Plot Appearance
cmap: str = 'jet'
cmap: str = "jet"
clim: Optional[Tuple[float, float]] = field(default_factory=lambda: (None, None))
color: List[str] = field(default_factory=lambda: ['blue', 'red'])
linestyle: List[str] = field(default_factory=lambda: ['solid', 'dashed'])
Expand Down
3 changes: 1 addition & 2 deletions pyprocar/cfg/fermi_surface_2d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ plot_color_bar:

cmap:
description: The colormap used for the plot.
value: jet
value: magma

value: jet
clim:
description: The color scale for the color bar
value:
Expand Down
3 changes: 2 additions & 1 deletion pyprocar/core/fermisurface.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def __init__(self, kpoints, bands, spd,
self.log.debug("FermiSurface.init: ...Done")

config_manager=ConfigManager(os.path.join(ROOT,'pyprocar','cfg','fermi_surface_2d.yml'))
config_manager.update_config(kwargs)

config_manager.update_config(kwargs)
self.config=config_manager.get_config()
return None

Expand Down
11 changes: 6 additions & 5 deletions pyprocar/scripts/scriptFermi2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
from matplotlib import colors as mpcolors
from matplotlib import cm

from ..core import ProcarSymmetry, FermiSurface
from ..utils import welcome, ROOT
from .. import io
from pyprocar.core import ProcarSymmetry, FermiSurface
from pyprocar.utils import welcome, ROOT
from pyprocar import io
from pyprocar.utils.plot_utils import DEFAULT_COLOR_MAP

with open(os.path.join(ROOT,'pyprocar','cfg','fermi_surface_2d.yml'), 'r') as file:
plot_opt = yaml.safe_load(file)

plot_opt['cmap'] = DEFAULT_COLOR_MAP

def fermi2D(
code:str,
dirname:str,
Expand Down Expand Up @@ -159,8 +162,6 @@ def fermi2D(
"""
)



if structure.rotations is not None:
ebs.ibz2fbz(structure.rotations)

Expand Down
81 changes: 81 additions & 0 deletions pyprocar/utils/plot_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import matplotlib.colors as mcolors
import matplotlib.pyplot as plt

# Credits to https://github.com/karthik/wesanderson
wes_anderson_palettes = {
"BottleRocket1": [
"#A42820",
"#5F5647",
"#9B110E",
"#3F5151",
"#4E2A1E",
"#550307",
"#0C1707",
],
"BottleRocket2": ["#FAD510", "#CB2314", "#273046", "#354823", "#1E1E1E"],
"Rushmore1": ["#E1BD6D", "#EABE94", "#0B775E", "#35274A", "#F2300F"],
"Rushmore": ["#E1BD6D", "#EABE94", "#0B775E", "#35274A", "#F2300F"],
"Royal1": ["#899DA4", "#C93312", "#FAEFD1", "#DC863B"],
"Royal2": ["#9A8822", "#F5CDB4", "#F8AFA8", "#FDDDA0", "#74A089"],
"Zissou1": ["#3B9AB2", "#78B7C5", "#EBCC2A", "#E1AF00", "#F21A00"],
"Zissou1Continuous": [
"#3A9AB2",
"#6FB2C1",
"#91BAB6",
"#A5C2A3",
"#BDC881",
"#DCCB4E",
"#E3B710",
"#E79805",
"#EC7A05",
"#EF5703",
"#F11B00",
],
"Darjeeling1": ["#FF0000", "#00A08A", "#F2AD00", "#e66f0e", "#5BBCD6"],
"Darjeeling2": ["#ECCBAE", "#046C9A", "#D69C4E", "#ABDDDE", "#000000"],
"Darjeeling1_alt": ["#e52207", "#00a398", "#e5a000", "#ABDDDE", "#59b9de"],
"Chevalier1": ["#446455", "#FDD262", "#D3DDDC", "#C7B19C"],
"FantasticFox1": ["#DD8D29", "#E2D200", "#46ACC8", "#E58601", "#B40F20"],
"Moonrise1": ["#F3DF6C", "#CEAB07", "#D5D5D3", "#24281A"],
"Moonrise2": ["#798E87", "#C27D38", "#CCC591", "#29211F"],
"Moonrise3": ["#85D4E3", "#F4B5BD", "#9C964A", "#CDC08C", "#FAD77B"],
"Cavalcanti1": ["#D8B70A", "#02401B", "#A2A475", "#81A88D", "#972D15"],
"GrandBudapest1": ["#F1BB7B", "#FD6467", "#5B1A18", "#D67236"],
"GrandBudapest2": ["#E6A0C4", "#C6CDF7", "#D8A499", "#7294D4"],
"IsleofDogs1": ["#9986A5", "#79402E", "#CCBA72", "#0F0D0E", "#D9D0D3", "#8D8680"],
"IsleofDogs2": ["#EAD3BF", "#AA9486", "#B6854D", "#39312F", "#1C1718"],
"FrenchDispatch": ["#90D4CC", "#BD3027", "#B0AFA2", "#7FC0C6", "#9D9C85"],
"AsteroidCity1": ["#0A9F9D", "#CEB175", "#E54E21", "#6C8645", "#C18748"],
"AsteroidCity2": ["#C52E19", "#AC9765", "#54D8B1", "#b67c3b", "#175149", "#AF4E24"],
"AsteroidCity3": ["#FBA72A", "#D3D4D8", "#CB7A5C", "#5785C1"],
}


# Function to set a specific color palette
def set_palette(palette_name):
if palette_name in wes_anderson_palettes:
plt.rcParams["axes.prop_cycle"] = plt.cycler(
color=wes_anderson_palettes[palette_name]
)
else:
print(f"Palette '{palette_name}' not found.")


# Function to create a custom colormap from a palette
def create_colormap(palette_name):
if palette_name in wes_anderson_palettes:
return mcolors.LinearSegmentedColormap.from_list(
palette_name, wes_anderson_palettes[palette_name]
)
else:
print(f"Palette '{palette_name}' not found.")
return None


# DEFAULT_COLOR_MAP = mcolors.LinearSegmentedColormap.from_list(
# "", wes_anderson_palettes["Zissou1Continuous"]
# )
DEFAULT_COLORS = wes_anderson_palettes["Darjeeling1"]
DEFAULT_COLORS.extend(wes_anderson_palettes["Darjeeling2"])
plt.rcParams["axes.prop_cycle"] = plt.cycler(color=DEFAULT_COLORS)
DEFAULT_COLOR_MAP = create_colormap("Zissou1Continuous")

0 comments on commit cf696d9

Please sign in to comment.