MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.39k stars 302 forks source link

Odd behavior when data includes -Inf values #2381

Open klaff opened 1 year ago

klaff commented 1 year ago

The following code:

using CairoMakie
using FFTW

N = 500
ma4 = [zeros(N÷2-2); 0.25 .* ones(4); zeros(N÷2-2)]
fig = Figure()
ax1 = Axis(fig[1,1])
xdata = rfftfreq(N)
ydata = 20log10.(abs.(rfft(ma4))) # ydata has two points at -Inf
#lines!(ax1, xdata, ydata) # this plots with erroneous x-axis scaling
#lines!(ax1, xdata, clamp.(ydata, -1e38, 1)) # this plots with strange retraces
lines!(ax1, xdata, clamp.(ydata, -1e37, 1)) # this plots as desired
ylims!(ax1, -45, 1)
fig

produces the desired result image when executed as shown above (where the ydata is clamped to not go below -1e37, but give this result (in which the x scaling seems to depend upon y data) image if the lines!(ax1, xdata, ydata) is used, and gives this result (with weird retrace lines) image if lines!(ax1, xdata, clamp.(ydata, -1e38, 1) is used.

klaff commented 1 year ago

Environment is CairoMakie v0.9.1 within Pluto v0.7.48 in Chrome under Windows 11.

klaff commented 1 year ago

BTW, I tried to make a more minimal MWE using a dozen or so points with one or two -Infs but could not replicate the issue so I left in the FFTW stuff.

asinghvi17 commented 1 year ago

Retrace lines are probably a Cairo thing, since -Inf in the y axis of Cairo is actually at the top. The projection code would probably be where one would look at for something like this.