I'd like to open a window and display an image, in full resolution on a retina display, on MacOS.
I can't find a way to do this, so I'm looking for a solution. I don't mind if it's via matplotlib or Tk or anything else. I don't need the script to do anything apart from generate the image and display it until I close the window. The image is stored in a NumPy array.
Note, this isn't quite as trivial as it sounds. It's not just a case of resizing the image, it's a case of changing the mode that the window is displayed in. This is an OS feature, and so it's a question of whether there are any Python libraries that support activating retina mode and displaying an image using it.
I've mostly tried poking around with Matplotlib, changing the backend and the figure.dpi
in the rcparams
, but it didn't seem to have any effect. It's difficult to google for solutions, because most people are using Jupyter notebooks but I really just want to use a script.
I'd like to open a window and display an image, in full resolution on a retina display, on MacOS.
I can't find a way to do this, so I'm looking for a solution. I don't mind if it's via matplotlib or Tk or anything else. I don't need the script to do anything apart from generate the image and display it until I close the window. The image is stored in a NumPy array.
Note, this isn't quite as trivial as it sounds. It's not just a case of resizing the image, it's a case of changing the mode that the window is displayed in. This is an OS feature, and so it's a question of whether there are any Python libraries that support activating retina mode and displaying an image using it.
I've mostly tried poking around with Matplotlib, changing the backend and the figure.dpi
in the rcparams
, but it didn't seem to have any effect. It's difficult to google for solutions, because most people are using Jupyter notebooks but I really just want to use a script.
As this is specifically for MacOS you can use its built-in open command.
When you open an image, the action will (by default) use Preview to display the image. Optionally you can specify an application to manage the relevant file.
Here's an example where you can open an image using its default application and also Safari.
import subprocess
image = "foo.jpg"
# by default this will display the image using Preview
subprocess.run(f"open {image}".split())
# or, for example, open the image using Safari
subprocess.run(f"open -a Safari {image}".split())