Conversation
|
Denselines implements the method of Moritz and Fisher (2018). Closes #5427 @jkrumbiegel suggested that this be part of the Datashader recipe, however I opted to keep this separate at least for now. Usage example: using Dates
using Statistics
using WGLMakie
function example_data()
n_times = 100
n_series = 10000
t = range(0, 2π, n_times)
time_series = zeros(n_times, n_series)
# First group: constant frequency sine wave
for i in 1:div(n_series, 2)
time_series[:, i] = 2.0 .+ sin.(t) .+ 0.1 .* randn(n_times)
end
# Second group: increasing frequency and amplitude
for i in (div(n_series, 2)+1):n_series
freq = range(1, 10, n_times)
amp = range(0.5, 2, n_times)
time_series[:, i] = 1.0 .+ amp .* sin.(freq .* t) .+ 0.1 .* randn(n_times)
end
return time_series
end
f, ax, sp = denselines(example_data(); bins_x=200, bins_y=100, colormap=:plasma)
ax.xlabel = "Time"
ax.ylabel = "Value"
|
| pixels = bresenham_line(x1, y1, x2, y2) | ||
|
|
||
| for (px, py) in pixels | ||
| if 1 <= px <= bins_x && 1 <= py <= bins_y | ||
| dense_mat[px, py] = 1.0 | ||
| end | ||
| end |
There was a problem hiding this comment.
Couldn't we also skip the pixels vector here and directly write to the matrix? That should save quite a bit of GC time I'd imagine.
Similarly, compute_normalized_density could probably clear and write to a matrix created once in denseline_data instead of creating a new one for every set of points
There was a problem hiding this comment.
I still think it might make sense to reuse the datashader infra for this if at all possible
There was a problem hiding this comment.
I've made changes for performance.
@jkrumbiegel , is a barrier function all you have in mind when you say "reuse the datashader infra"?
EDIT to add before and after:
Before: 1.797718 seconds (2.06 M allocations: 1.673 GiB, 29.31% gc time)
After: 0.377040 seconds (60.37 k allocations: 3.668 MiB)

Description
Adds a new
DenseLinesrecipe for visualizing time series data as a density line chart, based on the Moritz and Fisher method. It calculates and displays the density of overlapping lines, providing insights into data distribution over time.Type of change
Checklist