Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
KrylovKit = "0b1a1467-8014-51b9-945f-bf0ae24f4b77"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[weakdeps]
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

[extensions]
MeanFieldGraphPlotsExt = "Plots"

[compat]
Clustering = "0.15.7"
Distributions = "0.25"
Expand Down
19 changes: 19 additions & 0 deletions ext/MeanFieldGraphPlotsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module MeanFieldGraphPlotsExt

using MeanFieldGraph
using Plots: heatmap, palette
import MeanFieldGraph: plot

function plot(data::MeanFieldGraph.DiscreteTimeData)
N, T = size(data)
return heatmap(
data.X;
color=palette(:binary),
xticks=floor.(Int, range(1, T, 10)),
yticks=floor.(Int, range(1, N, 10)),
colorbar=:false,
tick_direction=:none,
)
end

end
1 change: 0 additions & 1 deletion src/MeanFieldGraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module MeanFieldGraph
using Clustering: Clustering, ClusteringResult, assignments, counts, kmeans, hclust, cutree
using Distributions: Distributions, Bernoulli, DiscreteUniform, fit, mean
using LinearAlgebra: LinearAlgebra, I, transpose
using Plots: Plots, heatmap, palette, plot
using KrylovKit: KrylovKit, svdsolve

export MarkovChainModel, DiscreteTimeData, MarkovChainConnectivity
Expand Down
21 changes: 7 additions & 14 deletions src/plots.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import Plots.plot

"""
plot(data::DiscreteTimeData)

Plot a black and white image corresponding to `data`. Black pixels correspond to the value `1`. The x-axis correspond to time and y-axis correspond to components.
Plot a black and white image corresponding to `data`. Black pixels correspond to
the value `1`. The x-axis corresponds to time and y-axis corresponds to
components.

The concrete plotting implementation is provided by a package extension when
`Plots` is available.
"""
function plot(data::DiscreteTimeData)
N, T = size(data)
return heatmap(
data.X;
color=palette(:binary),
xticks=floor.(Int, range(1, T, 10)),
yticks=floor.(Int, range(1, N, 10)),
colorbar=:false,
tick_direction=:none,
)
end
function plot end
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Clustering = "0.15"
Distributions = "0.25"
LinearAlgebra = "1"
Plots = "1"
Random = "1"
Test = "1"
julia = "1.6"
10 changes: 10 additions & 0 deletions test/plots.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@testset "Plot extension" begin
try
using Plots
data = MF.DiscreteTimeData(trues(4, 6))
fig = MF.plot(data)
@test fig !== nothing
catch e
@test_skip "Plots is not installed in active environment"
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ using Test
include("simulate.jl")
include("estimation.jl")
include("classification.jl")
include("plots.jl")
end
Loading