From 6a470dd9b1f744370c411411bb93ce2a1ad2e598 Mon Sep 17 00:00:00 2001 From: Mohammed Sadique Date: Mon, 10 Mar 2025 20:13:22 +0530 Subject: [PATCH 1/2] kickstart --- lib/matplotex.ex | 5 +++++ lib/matplotex/figure/areal/heatmap.ex | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 lib/matplotex/figure/areal/heatmap.ex diff --git a/lib/matplotex.ex b/lib/matplotex.ex index 5cd6d7d..aa57e01 100644 --- a/lib/matplotex.ex +++ b/lib/matplotex.ex @@ -161,6 +161,7 @@ defmodule Matplotex do """ + alias Nx.Heatmap alias Matplotex.Figure.Areal.PlotOptions alias Matplotex.Figure.Areal.Spline alias Matplotex.Figure.Areal.Histogram @@ -626,6 +627,10 @@ defmodule Matplotex do def step(x, y, opts), do: Matplotex.Figure.Areal.Step.create(x, y, opts) def step(figure, x, y, opts), do: Matplotex.Figure.Areal.Step.create(figure, x, y, opts) + # def heatmap(data, opts \\ []) do + # Matplotex.Figure.Areal.Heatmap.create(%Figure{axes: , }) + + # end @doc """ Sets X labels for the graph with given font details diff --git a/lib/matplotex/figure/areal/heatmap.ex b/lib/matplotex/figure/areal/heatmap.ex new file mode 100644 index 0000000..b6f3297 --- /dev/null +++ b/lib/matplotex/figure/areal/heatmap.ex @@ -0,0 +1,27 @@ +defmodule Matplotex.Figure.Areal.Heatmap do + @moduledoc false + + alias Matplotex.Figure.Areal.Region + alias Matplotex.Figure + alias Matplotex.Figure.Areal + alias Matplotex.Figure.TwoD + use Areal + frame( + tick: %TwoD{}, + limit: %TwoD{}, + label: %TwoD{}, + region_x: %Region{}, + region_y: %Region{}, + region_title: %Region{}, + region_legend: %Region{}, + region_content: %Region{} + ) + + @impl Areal + def create(%Figure{axes: %__MODULE__{dataset: dataset} = axes } = figure, data, opts) do + {rows, columns} = data|> Nx.tensor()|>Nx.size() + rows_idx = Nx.iota({rows, columns}, axis: 0) + columns_idx = Nx.iota({}) + + end +end From 22fed00976dc475b713e9463e067d77b3b44cc7a Mon Sep 17 00:00:00 2001 From: Mohammed Sadique Date: Thu, 13 Mar 2025 18:29:59 +0530 Subject: [PATCH 2/2] added data --- lib/matplotex/figure/areal/heatmap.ex | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/matplotex/figure/areal/heatmap.ex b/lib/matplotex/figure/areal/heatmap.ex index b6f3297..8118dd9 100644 --- a/lib/matplotex/figure/areal/heatmap.ex +++ b/lib/matplotex/figure/areal/heatmap.ex @@ -19,9 +19,20 @@ defmodule Matplotex.Figure.Areal.Heatmap do @impl Areal def create(%Figure{axes: %__MODULE__{dataset: dataset} = axes } = figure, data, opts) do - {rows, columns} = data|> Nx.tensor()|>Nx.size() - rows_idx = Nx.iota({rows, columns}, axis: 0) - columns_idx = Nx.iota({}) + data_tensor = data|> Nx.tensor() + {rows, columns} = data_tensor|>Nx.size() + row_indices = Nx.iota({rows, columns}, axis: 0) + column_indices = Nx.iota({rows, columns }, axis: 1) + row_flat = Nx.flatten(row_indices) + col_flat = Nx.flatten(column_indices) + values = Nx.flatten(data_tensor) + dataset = Dataset.cast(%Dataset{x: row_flat, y: column_flat, colours: values}, opts) |>Dataset.update_cmap() + datasets = data ++ [dataset] + xydata = flatten_for_data(datasets) + %Figure{figure | axes: %{axes | data: xydata, dataset: datasets}} + |> PlotOptions.set_options_in_figure(opts) end + + def materialyze(figure), do: figure end