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

Kpath heatmaps with PlotlyJS #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Kpath heatmaps with PlotlyJS #24

wants to merge 1 commit into from

Conversation

lxvm
Copy link

@lxvm lxvm commented Apr 5, 2023

Hi, I think the k-path visualization utilities for band plots are great, and I wanted to add a capability for plotting heatmaps, which can be helpful to visualize spectral densities. This pr refactors the k-path plotting code to make this additional capability a straightforward extension of the existing code. An example of what it can do follows from the tutorial in the documentation, which sets up the following

using PlotlyJS
using Brillouin
sgnum = 227
Rs = [[1,0,0], [0,1,0], [0,0,1]] # conventional direct basis
kp = irrfbz_path(sgnum, Rs)

function ϵ(k; γ::Real=1.0)
    kx = 2π*(-k[1]+k[2]+k[3])
    ky = 2π*(+k[1]-k[2]+k[3])
    kz = 2π*(+k[1]+k[2]-k[3])
    return 4γ * (cos(kx/2)*cos(ky/2) + cos(ky/2)*cos(kz/2) + cos(kz/2)*cos(kx/2))
end

If we now define a spectral density

A(k, ω; η::Real=0.1) = -imag(inv(complex(ω,η) - ϵ(k)))/pi

and evaluate it on a discretization

kpi = interpolate(kp, 500)
ω = range(-5,15,length=500)
dat = A.(kpi, ω')

this pr allows plotting with the following command

plot(kpi, ω, [dat])

image
and it is also possible to overlay multiple heatmaps with different colors, although what to do with the colorbar in this situation is undefined

dat2 = A.(kpi, (ω .+ 2)')
plot(kpi, ω, [dat, dat2]; opacity=0.5, colorscale=["YlOrRd", "YlGnBu"], reversescale=true)

image
I hope this is useful and I am happy to take comments on how to tweak this.

I was also hoping to ask a side question: what does the Makie extension provide?

@codecov-commenter
Copy link

codecov-commenter commented Apr 5, 2023

Codecov Report

Merging #24 (88eb405) into master (7363a2e) will increase coverage by 0.33%.
The diff coverage is 67.24%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master      #24      +/-   ##
==========================================
+ Coverage   84.26%   84.59%   +0.33%     
==========================================
  Files          14       14              
  Lines         953      987      +34     
==========================================
+ Hits          803      835      +32     
- Misses        150      152       +2     
Impacted Files Coverage Δ
ext/BrillouinPlotlyJSExt/dispersion.jl 77.77% <67.24%> (-14.73%) ⬇️

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@thchr
Copy link
Owner

thchr commented Jun 28, 2023

Hi Lorenzo,

Sorry I forgot this - and thanks for making this PR.

I think this is really nice and useful functionality. I wonder though, if it should have a different name than plot: initially, I thought this was coloring just a line as opposed to doing a heatmap. Maybe we could just call it heatmap and document it as such? If you're still up for this, I'd be happy to merge such a PR.

About the Makie question: I had been hoping to provide the same functionality via Makie as we do via PlotlyJS, but only got half-way.
Currently, the Makie extension includes methods to plot Wigner-Seitz cells/Brillouin zones and k-paths, but not band structures. The issue is that there isn't any way afaict to split a single plot call into multiple subplots in Makie. I.e., I cannot split the plot up if the k-path is disconnected. In principle, it could be hacked around I guess but I never got around to it.

@thchr
Copy link
Owner

thchr commented Jun 28, 2023

A minor thing: what is the motivation for having multiple distinct colormaps? The stacking of them with some opacity feels a little arbitrary (i.e., one will partly occlude the other?).

@lxvm
Copy link
Author

lxvm commented Jul 18, 2023

Hi @thchr,

Thank you for reviewing the PR.

Sure, I could rename the method plot(kpi::KPathInterpolant, ωs, fields, [layout]; kwargs...) to heatmap. The PlotlyJS API plots 'traces' that can be either curves or scalar fields, so when I implemented the PR I was mostly trying to expose that API (provided with the PlotlyJS.plot function) while keeping the all of the kpath customizations.

Thank you for the explanation on the Makie extension. I may try making some band structure figures and if it goes well I can make a separate PR.

Regarding multiple colormaps, I was thinking of using them to highlight different contributions to spectral densities (e.g. interband vs intraband conductivities). The colorscales would have to be chosen well for this to look good, but I thought it would be nice to make it work since PlotlyJS supports it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants