cjdoris / Bokeh.jl

Interactive plotting made easy
https://cjdoris.github.io/Bokeh.jl
Other
77 stars 3 forks source link

The Settings `dw_units` and `dh_units` Fail the Figure Rendering #27

Open RoyiAvital opened 1 year ago

RoyiAvital commented 1 year ago

Look at the following code:

Using Bokeh;
Bokeh.settings!(display="browser");

numRows = 500;
numCols = 500;

hF = figure();
plot!(hF, Image, image = [rand(numRows , numCols)], x = 0, y = 0, dw = numCols, dh = numRows);
display(hF);

This works and open a window with the noise rendered.

Now I want the image size to match the number of pixels in the data. So I need to set the units to screen:

Using Bokeh;
Bokeh.settings!(display="browser");

numRows = 500;
numCols = 500;

hF = figure();
plot!(hF, Image, image = [rand(numRows , numCols)], x = 0, y = 0, dw = numCols, dh = numRows, dw_units = "Screen", dh_units = "Screen");
display(hF);

Yet this time the browser window opens but nothing is displayed.

On Windows 10 with Julia 1.9.1 on a clean environment.

cjdoris commented 1 year ago

Does the equivalent plot work in Python?

AFAIR Bokeh.jl doesn't properly support units yet - I've never taken the time to understand how they work in bokeh.

RoyiAvital commented 1 year ago

@cjdoris , All I'm after is being able to set the number of pixels to be drawn. In MATLAB I can do it as axes(hF, 'Units', 'px', 'Position', [x, y, width, height]);.

I want to display images in Bokeh.jl and I need them to be 1:1. Namely each pixel of the image to be exactly a single pixel on the screen.

I thought dh_units are the way to do so.

RoyiAvital commented 1 year ago

I gave it a try using Python:

import numpy as np
from bokeh.plotting import figure, show

x = np.linspace(0, 10, 300)
y = np.linspace(0, 10, 300)
xx, yy = np.meshgrid(x, y)
d = np.sin(xx) * np.cos(yy)

p = figure(width=600, height=600, x_range = (0, 300), y_range = (0, 300))

p.image(image=[d], x=0, y=0, dw=300, dh=300, dw_units = 'screen', dh_units = 'screen', palette="Sunset11", level="image")
p.grid.grid_line_width = 0.5

show(p)

It indeed gives a 1:1 look. There is a different issue there, something I don't understand about the axis.
The image itself is perfectly aligned and its actual size on screen is 300x300.
So units indeed work on Python.