Note
Go to the end to download the full example code
Plotting with Configurations in pyprocar#
This example illustrates how to utilize various configurations for plotting the density of states (DOS) using the pyprocar package. It provides a structured way to explore and demonstrate different configurations for the dosplot function.
Preparation#
Before diving into plotting, we need to download the example files. Use the following code to do this. Once downloaded, specify the data_dir to point to the location of the downloaded data.
import pyprocar
data_dir = pyprocar.download_example(
save_dir='',
material='Fe',
code='vasp',
spin_calc_type='spin-polarized-colinear',
calc_type='dos'
)
import os
import pyprocar
# Define the directory containing the example data
code='vasp'
data_dir = f"{pyprocar.utils.ROOT}{os.sep}data{os.sep}examples{os.sep}Fe{os.sep}{code}{os.sep}spin-polarized-colinear{os.sep}dos"
spins=[0,1]
# Section 1: Locating and Printing Configuration Files
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# This section demonstrates where the configuration files are located in the package.
# It also shows how to print the configurations by setting print_plot_opts=True.
#
# Path to the configuration files in the package
config_path = os.path.join(pyprocar.__path__[0], 'cfg')
print(f"Configuration files are located at: {config_path}")
# Print the configurations
pyprocar.dosplot(code=code, dirname=data_dir,fermi=5.599480, print_plot_opts=True)
Configuration files are located at: z:\research projects\pyprocar\pyprocar\cfg
--------------------------------------------------------
There are additional plot options that are defined in a configuration file.
You can change these configurations by passing the keyword argument to the function
To print a list of plot options set print_plot_opts=True
Here is a list modes : plain , parametric , parametric_line , stack , stack_orbitals , stack_species
--------------------------------------------------------
cmap : {'description': 'The colormap used for the plot.', 'value': 'jet'}
colors : {'description': 'List of colors for the plot lines.', 'value': ['red', 'green', 'blue', 'cyan', 'magenta', 'yellow', 'orange', 'purple', 'brown', 'navy', 'maroon', 'olive']}
colorbar_title : {'description': 'Title of the colorbar.', 'value': 'Atomic Orbital Projections'}
colorbar_title_size : {'description': 'Font size of the title of the colorbar.', 'value': 15}
colorbar_title_padding : {'description': 'Padding of the title of the colorbar.', 'value': 20}
colorbar_tick_labelsize : {'description': 'Size of the title of the colorbar ticks', 'value': 10}
fermi_color : {'description': 'The color of the Fermi line.', 'value': 'black'}
fermi_linestyle : {'description': 'The linestyle of the Fermi line.', 'value': 'dotted'}
fermi_linewidth : {'description': 'The linewidth of the Fermi line.', 'value': 1}
figure_size : {'description': 'The size of the figure (width, height) in inches.', 'value': [9, 6]}
font : {'description': 'The font style for the plot text.', 'value': 'Arial'}
font_size : {'description': 'The size of the font used in the plot.', 'value': 16}
grid : {'description': 'If true, a grid will be shown on the plot.', 'value': False}
grid_axis : {'description': 'Which axis (or both) the grid lines should be drawn on.', 'value': 'both'}
grid_color : {'description': 'The color of the grid lines.', 'value': 'grey'}
grid_linestyle : {'description': 'The linestyle of the grid lines.', 'value': 'solid'}
grid_linewidth : {'description': 'The linewidth of the grid lines.', 'value': 1}
grid_which : {'description': 'Which grid lines to draw (major, minor or both).', 'value': 'major'}
legend : {'description': 'If true, a legend will be shown on the plot.', 'value': True}
linestyle : {'description': 'The linestyles for the plot lines.', 'value': ['solid', 'dashed']}
linewidth : {'description': 'The linewidths for the plot lines.', 'value': [1, 1]}
marker : {'description': 'The marker styles for the plot points.', 'value': ['o', 'v', '^', 'D']}
markersize : {'description': 'The size of the markers for the plot points.', 'value': [0.2, 0.2]}
opacity : {'description': 'The opacities for the plot lines.', 'value': [1.0, 1.0]}
plot_bar : {'description': 'If true, a bar plot will be displayed.', 'value': True}
plot_color_bar : {'description': 'If true, a color bar will be shown on the plot.', 'value': True}
plot_total : {'description': 'If true, the total plot will be displayed.', 'value': True}
savefig : {'description': 'The file name to save the figure. If null, the figure will not be saved.', 'value': None}
spin_colors : {'description': 'The colors for the spin up and spin down lines.', 'value': ['black', 'red']}
spin_labels : {'description': 'The labels for the spin up and spin down.', 'value': ['$\\uparrow$', '$\\downarrow$']}
title : {'description': 'The title for the plot. If null, no title will be displayed.', 'value': None}
verbose : {'description': 'If true, the program will print detailed information.', 'value': True}
weighted_color : {'description': 'If true, the color of the lines will be weighted.', 'value': True}
weighted_width : {'description': 'If true, the width of the lines will be weighted.', 'value': False}
clim : {'description': 'Value range to scale the colorbar', 'value': None}
stack_y_label : {'description': 'The label for the y-axis for stack mode', 'value': 'DOS'}
x_label : {'description': 'The label for the x-axis.', 'value': None}
y_label : {'description': 'The label for the y-axis.', 'value': None}
dpi : {'description': "The resolution in dots per inch. If 'figure', use the figure's dpi value.", 'value': 'figure'}
(<Figure size 900x600 with 1 Axes>, <Axes: xlabel='Energy - E$_F$ (eV)', ylabel='DOS'>)
# Section 2: Changing cmap, clim, and Fermi line properties
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# This section demonstrates how to change the colormap (cmap), color limits (clim),
# and Fermi line properties (color, linestyle, and linewidth).
#
pyprocar.dosplot(
code=code,
dirname=data_dir,
fermi=5.599480,
atoms=[0],
orbitals=[4,5,6,7,8],
mode='parametric',
cmap='viridis', # Colormap
clim=[0, 1], # Color limits
fermi_color='red', # Fermi line color
fermi_linestyle='--', # Fermi line linestyle
fermi_linewidth=2.0 # Fermi line linewidth
)
--------------------------------------------------------
There are additional plot options that are defined in a configuration file.
You can change these configurations by passing the keyword argument to the function
To print a list of plot options set print_plot_opts=True
Here is a list modes : plain , parametric , parametric_line , stack , stack_orbitals , stack_species
--------------------------------------------------------
(<Figure size 900x600 with 2 Axes>, <Axes: xlabel='Energy - E$_F$ (eV)', ylabel='DOS'>)
# Section 4: Setting the Figure Size and DPI
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# This section demonstrates how to set the figure size and dots per inch (DPI) for the plot.
#
pyprocar.dosplot(
code=code,
dirname=data_dir,
fermi=5.599480,
atoms=[0],
orbitals=[4,5,6,7,8],
mode='parametric_line',
figure_size=(10, 6), # Figure size (width, height)
dpi=300, # Dots per inch
grid=True, # Boolean for grid
)
--------------------------------------------------------
There are additional plot options that are defined in a configuration file.
You can change these configurations by passing the keyword argument to the function
To print a list of plot options set print_plot_opts=True
Here is a list modes : plain , parametric , parametric_line , stack , stack_orbitals , stack_species
--------------------------------------------------------
(<Figure size 1000x600 with 2 Axes>, <Axes: xlabel='Energy - E$_F$ (eV)', ylabel='DOS'>)
Total running time of the script: ( 0 minutes 1.736 seconds)