I’m new to nix and I’m using it in manjaro. So, as part of my learning I wanted to plot a simple random matrix using matplotlib
Here is the python code
import numpy as np
import matplotlib.pyplot as plt
# Create a matrix
matrix = np.random.rand(10, 10)
# Show the matrix
plt.imshow(matrix, cmap='viridis')
plt.colorbar()
plt.show()
and here is my flake.nix
{
description = "flake config for my prototype";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
nixgl.url = "github:nix-community/nixgl";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils , nixgl }:
let
system = "x86_64-linux";
pkgs = import nixpkgs {·
inherit system;·
overlays = [ nixgl.overlay ];
};
python = pkgs.python311;
arduino-cli = pkgs.arduino-cli;
in
{
devShells.${system}.default = pkgs.mkShell {
buildInputs = [·
pkgs.nixgl.nixGLIntel
python·
python.pkgs.pyserial
python.pkgs.numpy
python.pkgs.matplotlib
arduino-cli·
];
shellHook = ''
echo "Hello from the devShell"
'';
};
};
}
How I run the script
$ nix develop -i
$ python test.py
There is no output and no errors. nothing. my workaround is saving the plot into an image, but I have some projects that requires to display a plot dynamically, so I really need that functionality.
I tried the solution proposed in this other post, but I didn’t help. I would appreciate some tips. thanks