I like the package PlotlyJS
because of the good support of a secondary Y-axis.
Unfortunatly, I discovered that the savefig()
seems to be restricted in the number of points it can handle
and I don’t know if this is a PlotlyJS
or a Julia
-Issue.
In my case it is a frequency spectrum with 24’999’876 points.
This causes savefig()
to crash, the error messages are different, one is:
ERROR: Unexpected end of input
Line: 0
Around: ......
^
Below is my example. - You can check where your system fails, by modifyfing the factor before
the number of elements num_ = round(Int, 0.01 * 24999876)
:
using PlotlyJS
function _plot_single_spectra(num_::Int)
_amplitudes_Shunt = rand(num_)
_frequencies_Shunt = collect(range(1, num_))
_amplitudes_Hall = rand(num_)
_frequencies_Hall = collect(range(1, num_))
line_amplitudes_shunt = scatter(; x =_frequencies_Shunt, y = _amplitudes_Shunt, name = "Shunt")
line_amplitudes_hall = scatter(; x =_frequencies_Hall, y = _amplitudes_Hall, name = "Hall", yaxis="y2")
stem_frequ_Shunt_assumed = stem(; x = [0.4*num_], y = [1], name = "f_Shunt(assumed)")
stem_frequ_Hall_assumed = stem(; x = [0.6*num_], y = [1], name = "f_Hall(assumed)", yaxis="y2")
data = [line_amplitudes_shunt, line_amplitudes_hall, stem_frequ_Shunt_assumed, stem_frequ_Hall_assumed]
mylayout = Layout(
title_text = "FFT spectrum",
xaxis_title_text = "Frequency / Hz",
yaxis_title_text = "Amplitude Shunt",
# yaxis_type = "log",
yaxis2 = PlotlyJS.attr(
title = "Amplitude Hall",
# type = "log",
overlaying = "y",
side = "right"
)
)
# ---
return Plot(data, mylayout)
end
# ---
fn_plot = "c:/tmp/plt/test.pdf"
num_ = round(Int, 0.01 * 24999876)
# ---
hdl_plt = _plot_single_spectra(num_)
println("----- ready to save plot -----")
savefig(hdl_plt, fn_plot)
Has someone a proposal how to plot large amount of points with a 2nd y-Axis?
P.S.:
It might be that the main trouble maker is:
@ JSON.Parser C:\Users\...\.julia\packages\JSON\NeJ9k\src\Parser.jl:140