In material science, we frequently have to plot pole figures to know the symmetry of the as-grown thin film.
The Pole figure is a polar contour plot. I struggle to plot it in Julia. It would be a great help if someone helped me out.
The pole figure should look like:
But what I am getting is like
I m using the following script:
using DataFrames, Plots, DelimitedFiles, Glob, LaTeXStrings
f=Glob.glob("*.txt")
df=readdlm(f[1],comment_char='#',comments=true)
df=DataFrame(df,:auto)
Chi,phi,I=df[:,1],df[:,2],df[:,3]
plotlyjs()
c=contour(Chi,phi,I,fill=true,c=:Spectral,frame=:box,axis=:polar,xlabel=L"$\chi$",ylabel=L"$\phi$", width=1000, height=1000)
savefig(c,"pole122.png")
juliohm
December 16, 2021, 12:06pm
2
It is really nice to have polar coordinates implemented in Plots.jl:
using Plots; gr()
plot(linspace(0,3π,100), rand(100), proj=:polar, m=:red)
[polar]
and even nicer to interact with them using the PlotlyJS backend. However, I can’t find documentation on how to plot heatmaps and contour plots in polar coordinates. Could you please give a hand?
Maybe you want the option proj = :polar
.
Its not working, I am getting following error:
MethodError: no method matching heatmap_edges(::Vector{Float64}, ::Symbol, ::Vector{Float64}, ::Symbol, ::Tuple{Int64})
Closest candidates are:
heatmap_edges(::AbstractVector, ::Symbol, ::AbstractVector, ::Symbol, ::Tuple{Int64, Int64}) at C:\Users\usmaa\.julia\packages\Plots\FCM0H\src\utils.jl:304
heatmap_edges(::AbstractVector, ::Symbol, ::AbstractVector, ::Symbol, ::Tuple{Int64, Int64}, ::Bool) at C:\Users\usmaa\.julia\packages\Plots\FCM0H\src\utils.jl:304
heatmap_edges(::AbstractVector, ::Symbol) at C:\Users\usmaa\.julia\packages\Plots\FCM0H\src\utils.jl:294
juliohm
December 16, 2021, 1:04pm
4
Please share the exact code you tried to run and quote it in backquotes so that Discourse highlights it correctly.
I am using the following code (Julia 1.7.0).
using DataFrames, Plots, DelimitedFiles, Glob, LaTeXStrings
f=Glob.glob("*.txt")
df=readdlm(f[1],comment_char='#',comments=true)
df=DataFrame(df,:auto)
Chi,phi,I=df[:,1],df[:,2],df[:,3]
pyplot()
c=heatmap(Chi,phi,I,fill=true,c=:Spectral,frame=:box,proj=:polar,xlabel=L"$\chi$",ylabel=L"$\phi$", width=1000, height=1000)
savefig(c,"pole122.png")
It uses my data file , how do I share it
juliohm
December 16, 2021, 1:17pm
6
Ideally you don’t need to share a file, just create fake data and make a minimum working example. That way we can easily help without downloading data.
Plots.jl pyplot() backend works (see example here ) but with some limitations and PyPlot.jl seems to work best (see github post here ).
PyPlot example below:
using PyPlot
fig = plt.figure()
ax = fig.add_subplot(111, projection="polar")
ρ = LinRange(0., 7, 200)
θ = LinRange(0., 2π, 360)
funp(ρ,θ) = sin(2ρ) * cos(θ)
pc = pcolormesh(θ, ρ, funp.(ρ,θ'))
cbar = plt.colorbar(pc)
cbar.set_label("Intensity")
ax[:grid](true)
3 Likes
Thanks a lot, Rafael it works
jheinen
December 18, 2021, 1:25am
10
Also works in GR:
using GR
ρ = LinRange(0., 7, 200)
θ = LinRange(0., 2π, 360)
funp(ρ,θ) = sin(2ρ) * cos(θ)
polarheatmap(funp.(ρ,θ'))
4 Likes
Thanks, Jheinen. This solution also works, but how could one change other plot properties like color and levels
@jheinen , what do the labels 100.5 and 0.5 mean?
jheinen
December 18, 2021, 7:30am
13
Those labels are derived from the ρ range. It’s a bug
Don’t you have to specify the polar coordinates here in order to get the correct ranges? See above how the similar PyPlot function was called.
jheinen
December 18, 2021, 9:10am
15
Thanks for the hint. I will change the heatmap
functions next week.
2 Likes
jheinen
February 11, 2022, 11:31pm
16
I think that’s fixed in the meantime:
using GR
ρ = LinRange(0., 7, 200)
θ = LinRange(0., 2π, 360)
funp(ρ,θ) = sin(2ρ) * cos(θ)
polarheatmap(ρ,θ,funp.(ρ,θ')')
4 Likes