We use plotly for interactive plotting. Data for plotly is obtained using `pivotpy.iplots.create_rgb_lines`.

  Index 
  Example 
  StaticPlots 
  InteractivePlots● 
  SpinProjectedSurfaces 
  StructureIO 
  Widgets 
  MainAPI 

iplot2html[source]

iplot2html(fig, filename=None, out_string=False, modebar=True)

  • Writes plotly's figure as HTML file or display in IPython which is accessible when online. It is different than plotly's fig.to_html as it is minimal in memory. If you need to have offline working file, just use fig.write_html('file.html') which will be larger in size.
  • Parameters
    • fig : A plotly's figure object.
    • filename : Name of file to save fig. Defualt is None and show plot in Colab/Online or return hrml string.
    • out_string: If True, returns HTML string, if False displays graph if possible.

iplot_rgb_lines[source]

iplot_rgb_lines(path_evr=None, elements=[[], [], []], orbs=[[], [], []], labels=['', '', ''], mode='markers', elim=[], Fermi=None, skipk=None, kseg_inds=[], max_width=6, title=None, ktick_inds=[0, -1], ktick_vals=['Γ', 'M'], figsize=None, interp_nk={}, query_data={})

  • Returns plotly's figure object, takes care of spin-polarized calculations automatically. elements,orbs and labels are required to be one-to-one lists of size 3 where each item in list could be another list or integer.
  • Parameters

    • path_evr : Path/to/vasprun.xml or xml output of read_asxml.
    • elements : List of size 3 of list of indices of ions. If not given, picks all ions for each orbital.
    • orbs : List of size 3 of list of orbital indices, if not gievn, s,p,d plotted.
    • labels : List of labels for projection.
    • mode : Three plotting modes are available:

      • 'markers' : Plot whole data as a single scatter object. Its too fast.
      • 'bands' : Plot data such that each band is accessible via legend.
      • 'lines' : A replica of matplotlib LineCollection object. It plots at each point separately, slower than other two modes.
    • interp_nk : Dictionary with keys 'n' and 'k' for interpolation.

    • figsize : Tuple(width,height) in pixels, e.g. (700,400).
    • query_data : Dictionary with keys as label and values as list of length 2. len(query_data) <=3 should hold for RGB plots. If given, used in place of elements, orbs and labels arguments.
                Example: {'s':([0,1],[0]),'p':([0,1],[1,2,3]),'d':([0,1],[4,5,6,7,8])} will pick up s,p,d orbitals of first two ions of system.
    • Other Parameters
      • ktick_inds, ktick_vals,elim,kseg_inds,max_width,title etc.
import os 
import pivotpy as pp 
os.chdir('E:/Research/graphene_example/ISPIN_1/bands')
fig=iplot_rgb_lines(mode='markers',elim=[-10,10],orbs=[[0],[1],[2,3]],labels=['s','p<sub>z</sub>','p<sub>x</sub>+p<sub>y</sub>'], 
                    ktick_inds=[0,30,60,-1],ktick_vals=['Γ','M','K','Γ'],Fermi=-2.7735,max_width=16)
iplot2html(fig,modebar=False)
c:\users\mass_\appdata\local\programs\python\python37\lib\site-packages\ipykernel_launcher.py:31: DeprecationWarning:

elementwise comparison failed; this will raise an error in the future.

Creating a grid plot using iplot_rgb_lines

  • Here is a workaround if you want to plot multiple axes like matplotlib. You can add traces to plotly's make_subplots object by getting data=iplot_rgb_lines().data and layout=iplot_rgb_lines().layout objects. See example below:
import plotly.graph_objects as go 
from IPython.display import HTML
import pivotpy.iplots as ips
import os 
from plotly.subplots import make_subplots

os.chdir('E:/Research/graphene_example/ISPIN_1/bands')
inds=[0,30,60,-1]
lbs=['Γ','M','K','Γ']
kargs=dict(mode='markers',elim=[-10,10],ktick_inds=inds,ktick_vals=lbs)
fig5 = make_subplots(rows=2, cols=2,shared_yaxes=True,shared_xaxes=True,
    horizontal_spacing=0.08,
    vertical_spacing=0.1,
    subplot_titles=['s','pz','py','s,p,d'],
    column_widths=[1,2],
    row_heights=[1,2],
    y_title='Energy (eV)'
                                  )
[fig5.add_trace(trace,row=1,col=1) for trace in ips.iplot_rgb_lines(orbs=[0,[],[]],**kargs).data]
[fig5.add_trace(trace,row=1,col=2) for trace in ips.iplot_rgb_lines(orbs=[[],[1],[]],**kargs).data]
[fig5.add_trace(trace,row=2,col=1) for trace in ips.iplot_rgb_lines(orbs=[[],[],[2]],**kargs).data]
last=ips.iplot_rgb_lines(**kargs)
[fig5.add_trace(trace,row=2,col=2) for trace in last.data]
fig5.update_layout(width=600,height=400,font=last.layout.font,margin=dict(r=10,l=10,t=40,b=40))
fig5.update_xaxes(last.layout.xaxis)
last.layout.yaxis.title=''
fig5.update_yaxes(last.layout.yaxis)
iplot2html(fig5,modebar=False)

Click on gridplot.html to see the plot generated from above code.

Using _collect_dos in Plotly

  • A function similar to splot_dos_lines is created in plotly below. Plotly will reduce number of parameters and you are able to tweek those parameters interactively in graph.

iplot_dos_lines[source]

iplot_dos_lines(path_evr=None, elements=[[0]], orbs=[[0]], labels=['s'], elim=[], colormap='gist_rainbow', tdos_color=(0.5, 0.95, 0), linewidth=2, fill_area=True, vertical=False, Fermi=None, figsize=None, spin='both', interp_nk={}, title=None, query_data={})

  • Returns plotly's figure. If given,elements,orbs colors, and labels must have same length. If not given, zeroth ions is plotted with s-orbital.
  • Parameters)
    • path_evr : Path/to/vasprun.xml or output of export_vasprun. Auto picks in CWD.
    • elements : List [[0,],] of ions indices, by defualt plot first ion's projections.
    • orbs : List [[0,],] lists of indices of orbitals, could be empty.
    • labels : List [str,] of orbitals labels. len(labels) == len(orbs) must hold.
    • elim : [min,max] of energy range.
    • Fermi : If not given, automatically picked from export_vasprun.
    • colormap : Matplotlib's standard color maps. Default is 'gist_ranibow'. Use 'RGB' if want to compare with iplot_rgb_lines with 3 projection inputs (len(orbs)==3).
    • fill_area : Default is True and plots filled area for dos. If False, plots lines only.
    • vertical : False, If True, plots along y-axis.
    • interp_nk : Dictionary with keys 'n' and 'k' for interpolation.
    • figsize : Tuple(width,height) in pixels, e.g. (700,400).
    • query_data : Dictionary with keys as label and values as list of length 2. If given, used in place of elements, orbs and labels arguments.
            Example: {'s':([0,1],[0]),'p':([0,1],[1,2,3]),'d':([0,1],[4,5,6,7,8])} will pick up s,p,d orbitals of first two ions of system.
  • Returns
    • fig : Plotly's figure object.
import pivotpy as pp 
fig=iplot_dos_lines(path_evr='E:/Research/graphene_example/ISPIN_2/dos/vasprun.xml',vertical=False,fill_area=True,elements=[[0],[1],[]],orbs=[0,1,[2,3]],labels=['C1-s','C2-p<sub>z</sub>','None-p<sub>x</sub>+p<sub>y</sub>'],figsize=(700,550),colormap='RGB')
iplot2html(fig,modebar=False)

  Index 
  Example 
  StaticPlots 
  InteractivePlots● 
  SpinProjectedSurfaces 
  StructureIO 
  Widgets 
  MainAPI