DataRange1d flipped attribute

Hi,

I’ve been trying to display an image and flip the axes using the DataRange1d ‘flipped’ attribute. It isn’t working, don’t know if that’s just because I’m not using it properly. Here’s the code…

···

from bokeh.io import show
from bokeh.models.ranges import DataRange1d
from bokeh.plotting import Figure
from bokeh.models.mappers import LinearColorMapper
from bokeh.palettes import RdYlBu11
import numpy

Test data

x = numpy.linspace(1,2,4)
y = numpy.linspace(2,4,6)
z = numpy.zeros([x.size,y.size])
for i in range(x.size):
for j in range(y.size):
z[i,j] = (x[i]*y[j])**2

Flipped ranges

xr = DataRange1d(start = x[0],end = x[-1])
xr.flipped = True
yr = DataRange1d(start = y[0],end = y[-1])
yr.flipped = True

Plot

f = Figure(x_range = xr,y_range = yr)
cm = LinearColorMapper(palette = RdYlBu11)
f.image([z.T],x[0],y[0],dw=x[-1]-x[0],dh=y[-1]-y[0],color_mapper=cm)

show(f)


The result is in the attached file test_image.png. I was expecting the image to be flipped in x and y (i.e. the red colour should be in the bottom-left hand corner) and the axes labels flipped accordingly, but this didn’t happen. Any advice gratefully received,

Marcus.

Hi Marcus,

z = numpy.flipud(z) will do the trick for you.

Raphael

···

On 2016-09-01 17:30, Marcus Donnelly
wrote:

Hi,

    I've been trying to display an image and flip the axes using the

DataRange1d ‘flipped’ attribute. It isn’t working, don’t know if
that’s just because I’m not using it properly. Here’s the
code…

    -----



    from bokeh.io import show

    from bokeh.models.ranges import DataRange1d

    from bokeh.plotting import Figure

    from bokeh.models.mappers import LinearColorMapper

    from bokeh.palettes import RdYlBu11

    import numpy



    # Test data

    x = numpy.linspace(1,2,4)

    y = numpy.linspace(2,4,6)

    z = numpy.zeros([x.size,y.size])

    for i in range(x.size):

        for j in range(y.size):

            z[i,j] = (x[i]*y[j])**2



    # Flipped ranges

    xr = DataRange1d(start = x[0],end = x[-1])

    xr.flipped = True

    yr = DataRange1d(start = y[0],end = y[-1])

    yr.flipped = True



    # Plot

    f = Figure(x_range = xr,y_range = yr)

    cm = LinearColorMapper(palette = RdYlBu11)

f.image([z.T],x[0],y[0],dw=x[-1]-x[0],dh=y[-1]-y[0],color_mapper=cm)

    show(f)



    -----



    The result is in the attached file test_image.png. I was

expecting the image to be flipped in x and y (i.e. the red
colour should be in the bottom-left hand corner) and the axes
labels flipped accordingly, but this didn’t happen. Any advice
gratefully received,

    Marcus.

  You received this message because you are subscribed to the Google

Groups “Bokeh Discussion - Public” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to [email protected].

  To post to this group, send email to [email protected].

  To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/f05cc6b8-1289-4eec-809e-586cc29a628f%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/f05cc6b8-1289-4eec-809e-586cc29a628f%40continuum.io?utm_medium=email&utm_source=footer).

  For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).

To elaborate, there's actually two considerations.

For the image itself, I believe there is a bug relating to flipped ranges specifically relating to images. The reason for this is that unlike every other kind of glyph that depends mapping individual coordinates from data to screen space, an image has to be flipped "as a whole". There is no code that does this yet, AFAIK. For now your best bet is to "flip" the image yourself as suggested by Raphael.

For the axes, the reason they are not flipped it because you are setting start and end values yourself. Setting flipped=True means that the axis orientation should be flipped *when auto-ranging is happening* But by setting start and end manually, you are overriding any auto-ranging. So, if you want the axes flipped, but want to set values yourself, then simply swap what you set for start/end. Of course, if you always want to set things yourself, and not rely on auto-ranging, then a simple Range1d will also suffice.

Bryan

···

On Sep 1, 2016, at 10:44 AM, Raphael Walker <[email protected]> wrote:

Hi Marcus,

z = numpy.flipud(z) will do the trick for you.

Raphael
On 2016-09-01 17:30, Marcus Donnelly wrote:

Hi,

I've been trying to display an image and flip the axes using the DataRange1d 'flipped' attribute. It isn't working, don't know if that's just because I'm not using it properly. Here's the code...

-----

from bokeh.io import show
from bokeh.models.ranges import DataRange1d
from bokeh.plotting import Figure
from bokeh.models.mappers import LinearColorMapper
from bokeh.palettes import RdYlBu11
import numpy

# Test data
x = numpy.linspace(1,2,4)
y = numpy.linspace(2,4,6)
z = numpy.zeros([x.size,y.size])
for i in range(x.size):
    for j in range(y.size):
        z[i,j] = (x[i]*y[j])**2

# Flipped ranges
xr = DataRange1d(start = x[0],end = x[-1])
xr.flipped = True
yr = DataRange1d(start = y[0],end = y[-1])
yr.flipped = True

# Plot
f = Figure(x_range = xr,y_range = yr)
cm = LinearColorMapper(palette = RdYlBu11)
f.image([z.T],x[0],y[0],dw=x[-1]-x[0],dh=y[-1]-y[0],color_mapper=cm)

show(f)

-----

The result is in the attached file test_image.png. I was expecting the image to be flipped in x and y (i.e. the red colour should be in the bottom-left hand corner) and the axes labels flipped accordingly, but this didn't happen. Any advice gratefully received,

Marcus.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f05cc6b8-1289-4eec-809e-586cc29a628f%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e528d570-a673-98ca-6943-518c897eb514%40busino.ch\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks Raphael. That’s one option, but the axes labels would still be incorrect.

Marcus.

···

On Thursday, September 1, 2016 at 5:00:46 PM UTC+1, Raphael Walker wrote:

Hi Marcus,

z = numpy.flipud(z) will do the trick for you.

Raphael

  On 2016-09-01 17:30, Marcus Donnelly > wrote:

Hi,

    I've been trying to display an image and flip the axes using the

DataRange1d ‘flipped’ attribute. It isn’t working, don’t know if
that’s just because I’m not using it properly. Here’s the
code…

    -----



    from [bokeh.io](http://bokeh.io) import show

    from bokeh.models.ranges import DataRange1d

    from bokeh.plotting import Figure

    from bokeh.models.mappers import LinearColorMapper

    from bokeh.palettes import RdYlBu11

    import numpy



    # Test data

    x = numpy.linspace(1,2,4)

    y = numpy.linspace(2,4,6)

    z = numpy.zeros([x.size,y.size])

    for i in range(x.size):

        for j in range(y.size):

            z[i,j] = (x[i]*y[j])**2



    # Flipped ranges

    xr = DataRange1d(start = x[0],end = x[-1])

    xr.flipped = True

    yr = DataRange1d(start = y[0],end = y[-1])

    yr.flipped = True



    # Plot

    f = Figure(x_range = xr,y_range = yr)

    cm = LinearColorMapper(palette = RdYlBu11)

f.image([z.T],x[0],y[0],dw=x[-1]-x[0],dh=y[-1]-y[0],color_mapper=cm)

    show(f)



    -----



    The result is in the attached file test_image.png. I was

expecting the image to be flipped in x and y (i.e. the red
colour should be in the bottom-left hand corner) and the axes
labels flipped accordingly, but this didn’t happen. Any advice
gratefully received,

    Marcus.

  You received this message because you are subscribed to the Google

Groups “Bokeh Discussion - Public” group.

  To unsubscribe from this group and stop receiving emails from it,

send an email to [email protected].

  To post to this group, send email to [email protected].

  To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/f05cc6b8-1289-4eec-809e-586cc29a628f%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/f05cc6b8-1289-4eec-809e-586cc29a628f%40continuum.io?utm_medium=email&utm_source=footer).

  For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).

That explains it, thanks Bryan. I did notice the when auto-ranging included in the reference for the DataRange1d flipped attribute, but didn’t realise I’d turned it off!

Marcus.

···

On Thursday, September 1, 2016 at 5:46:12 PM UTC+1, Bryan Van de ven wrote:

To elaborate, there’s actually two considerations.

For the image itself, I believe there is a bug relating to flipped ranges specifically relating to images. The reason for this is that unlike every other kind of glyph that depends mapping individual coordinates from data to screen space, an image has to be flipped “as a whole”. There is no code that does this yet, AFAIK. For now your best bet is to “flip” the image yourself as suggested by Raphael.

For the axes, the reason they are not flipped it because you are setting start and end values yourself. Setting flipped=True means that the axis orientation should be flipped when auto-ranging is happening But by setting start and end manually, you are overriding any auto-ranging. So, if you want the axes flipped, but want to set values yourself, then simply swap what you set for start/end. Of course, if you always want to set things yourself, and not rely on auto-ranging, then a simple Range1d will also suffice.

Bryan

On Sep 1, 2016, at 10:44 AM, Raphael Walker [email protected] wrote:

Hi Marcus,

z = numpy.flipud(z) will do the trick for you.

Raphael

On 2016-09-01 17:30, Marcus Donnelly wrote:

Hi,

I’ve been trying to display an image and flip the axes using the DataRange1d ‘flipped’ attribute. It isn’t working, don’t know if that’s just because I’m not using it properly. Here’s the code…


from bokeh.io import show

from bokeh.models.ranges import DataRange1d

from bokeh.plotting import Figure

from bokeh.models.mappers import LinearColorMapper

from bokeh.palettes import RdYlBu11

import numpy

Test data

x = numpy.linspace(1,2,4)

y = numpy.linspace(2,4,6)

z = numpy.zeros([x.size,y.size])

for i in range(x.size):

for j in range(y.size):
    z[i,j] = (x[i]*y[j])**2

Flipped ranges

xr = DataRange1d(start = x[0],end = x[-1])

xr.flipped = True

yr = DataRange1d(start = y[0],end = y[-1])

yr.flipped = True

Plot

f = Figure(x_range = xr,y_range = yr)

cm = LinearColorMapper(palette = RdYlBu11)

f.image([z.T],x[0],y[0],dw=x[-1]-x[0],dh=y[-1]-y[0],color_mapper=cm)

show(f)


The result is in the attached file test_image.png. I was expecting the image to be flipped in x and y (i.e. the red colour should be in the bottom-left hand corner) and the axes labels flipped accordingly, but this didn’t happen. Any advice gratefully received,

Marcus.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f05cc6b8-1289-4eec-809e-586cc29a628f%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e528d570-a673-98ca-6943-518c897eb514%40busino.ch.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

It might be worth adding a note that explicitly states that setting start/end manually disables auto-ranging. If you are interested in contributing to OSS then a small PR to update the docs would certainly be welcome. In case you are, the place where that documentation is generated from is here:

  https://github.com/bokeh/bokeh/blob/master/bokeh/models/ranges.py#L157-L159

Thanks,

Bryan

···

On Sep 1, 2016, at 11:59 AM, Marcus Donnelly <[email protected]> wrote:

That explains it, thanks Bryan. I did notice the when auto-ranging included in the reference for the DataRange1d flipped attribute, but didn't realise I'd turned it off!

Marcus.

On Thursday, September 1, 2016 at 5:46:12 PM UTC+1, Bryan Van de ven wrote:
To elaborate, there's actually two considerations.

For the image itself, I believe there is a bug relating to flipped ranges specifically relating to images. The reason for this is that unlike every other kind of glyph that depends mapping individual coordinates from data to screen space, an image has to be flipped "as a whole". There is no code that does this yet, AFAIK. For now your best bet is to "flip" the image yourself as suggested by Raphael.

For the axes, the reason they are not flipped it because you are setting start and end values yourself. Setting flipped=True means that the axis orientation should be flipped *when auto-ranging is happening* But by setting start and end manually, you are overriding any auto-ranging. So, if you want the axes flipped, but want to set values yourself, then simply swap what you set for start/end. Of course, if you always want to set things yourself, and not rely on auto-ranging, then a simple Range1d will also suffice.

Bryan

> On Sep 1, 2016, at 10:44 AM, Raphael Walker <[email protected]> wrote:
>
> Hi Marcus,
>
> z = numpy.flipud(z) will do the trick for you.
>
> Raphael
> On 2016-09-01 17:30, Marcus Donnelly wrote:
>> Hi,
>>
>> I've been trying to display an image and flip the axes using the DataRange1d 'flipped' attribute. It isn't working, don't know if that's just because I'm not using it properly. Here's the code...
>>
>> -----
>>
>> from bokeh.io import show
>> from bokeh.models.ranges import DataRange1d
>> from bokeh.plotting import Figure
>> from bokeh.models.mappers import LinearColorMapper
>> from bokeh.palettes import RdYlBu11
>> import numpy
>>
>> # Test data
>> x = numpy.linspace(1,2,4)
>> y = numpy.linspace(2,4,6)
>> z = numpy.zeros([x.size,y.size])
>> for i in range(x.size):
>> for j in range(y.size):
>> z[i,j] = (x[i]*y[j])**2
>>
>> # Flipped ranges
>> xr = DataRange1d(start = x[0],end = x[-1])
>> xr.flipped = True
>> yr = DataRange1d(start = y[0],end = y[-1])
>> yr.flipped = True
>>
>> # Plot
>> f = Figure(x_range = xr,y_range = yr)
>> cm = LinearColorMapper(palette = RdYlBu11)
>> f.image([z.T],x[0],y[0],dw=x[-1]-x[0],dh=y[-1]-y[0],color_mapper=cm)
>>
>> show(f)
>>
>> -----
>>
>> The result is in the attached file test_image.png. I was expecting the image to be flipped in x and y (i.e. the red colour should be in the bottom-left hand corner) and the axes labels flipped accordingly, but this didn't happen. Any advice gratefully received,
>>
>> Marcus.
>>
>> --
>> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
>> To post to this group, send email to bo...@continuum.io.
>> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f05cc6b8-1289-4eec-809e-586cc29a628f%40continuum.io\.
>> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
>
>
> --
> You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e528d570-a673-98ca-6943-518c897eb514%40busino.ch\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0a1aae63-d129-4c88-9dee-d4e3a5414bbe%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

I’m not currently a GitHub user but if I can work out how to do this (I’m sure it’s not too hard) I will!

Thanks again,
Marcus.

···

On Thursday, September 1, 2016 at 6:02:21 PM UTC+1, Bryan Van de ven wrote:

It might be worth adding a note that explicitly states that setting start/end manually disables auto-ranging. If you are interested in contributing to OSS then a small PR to update the docs would certainly be welcome. In case you are, the place where that documentation is generated from is here:

    [https://github.com/bokeh/bokeh/blob/master/bokeh/models/ranges.py#L157-L159](https://github.com/bokeh/bokeh/blob/master/bokeh/models/ranges.py#L157-L159)

Thanks,

Bryan

On Sep 1, 2016, at 11:59 AM, Marcus Donnelly [email protected] wrote:

That explains it, thanks Bryan. I did notice the when auto-ranging included in the reference for the DataRange1d flipped attribute, but didn’t realise I’d turned it off!

Marcus.

On Thursday, September 1, 2016 at 5:46:12 PM UTC+1, Bryan Van de ven wrote:

To elaborate, there’s actually two considerations.

For the image itself, I believe there is a bug relating to flipped ranges specifically relating to images. The reason for this is that unlike every other kind of glyph that depends mapping individual coordinates from data to screen space, an image has to be flipped “as a whole”. There is no code that does this yet, AFAIK. For now your best bet is to “flip” the image yourself as suggested by Raphael.

For the axes, the reason they are not flipped it because you are setting start and end values yourself. Setting flipped=True means that the axis orientation should be flipped when auto-ranging is happening But by setting start and end manually, you are overriding any auto-ranging. So, if you want the axes flipped, but want to set values yourself, then simply swap what you set for start/end. Of course, if you always want to set things yourself, and not rely on auto-ranging, then a simple Range1d will also suffice.

Bryan

On Sep 1, 2016, at 10:44 AM, Raphael Walker [email protected] wrote:

Hi Marcus,

z = numpy.flipud(z) will do the trick for you.

Raphael
On 2016-09-01 17:30, Marcus Donnelly wrote:

Hi,

I’ve been trying to display an image and flip the axes using the DataRange1d ‘flipped’ attribute. It isn’t working, don’t know if that’s just because I’m not using it properly. Here’s the code…


from bokeh.io import show
from bokeh.models.ranges import DataRange1d
from bokeh.plotting import Figure
from bokeh.models.mappers import LinearColorMapper
from bokeh.palettes import RdYlBu11
import numpy

Test data

x = numpy.linspace(1,2,4)
y = numpy.linspace(2,4,6)
z = numpy.zeros([x.size,y.size])
for i in range(x.size):
for j in range(y.size):
z[i,j] = (x[i]*y[j])**2

Flipped ranges

xr = DataRange1d(start = x[0],end = x[-1])
xr.flipped = True
yr = DataRange1d(start = y[0],end = y[-1])
yr.flipped = True

Plot

f = Figure(x_range = xr,y_range = yr)
cm = LinearColorMapper(palette = RdYlBu11)
f.image([z.T],x[0],y[0],dw=x[-1]-x[0],dh=y[-1]-y[0],color_mapper=cm)

show(f)


The result is in the attached file test_image.png. I was expecting the image to be flipped in x and y (i.e. the red colour should be in the bottom-left hand corner) and the axes labels flipped accordingly, but this didn’t happen. Any advice gratefully received,

Marcus.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f05cc6b8-1289-4eec-809e-586cc29a628f%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/e528d570-a673-98ca-6943-518c897eb514%40busino.ch.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/0a1aae63-d129-4c88-9dee-d4e3a5414bbe%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.