How do I change the center of rects?

I’ve been trying to modify the les_mis example to use my own data (cf les_mis — Bokeh 0.10.0 documentation )

However, my plots are getting cut off at the min axes, eg http://i.imgur.com/KZ05gmZ.jpg

I’m not sure what’s going on and someone else recently ran into the exact same problem here: http://stackoverflow.com/questions/33936852/python-bokeh-offset-with-rect-plotting

Any idea what we are missing?

Can you provide a minimal, runnable example that reproduces what you are seeing? It's difficult to offer advice or to debug without that.

Bryan

···

On Dec 10, 2015, at 11:12 AM, Ryan Compton <[email protected]> wrote:

I've been trying to modify the les_mis example to use my own data (cf les_mis — Bokeh 0.10.0 documentation )

However, my plots are getting cut off at the min axes, eg http://i.imgur.com/KZ05gmZ.jpg

I'm not sure what's going on and someone else recently ran into the exact same problem here: matrix - python bokeh offset with rect plotting - Stack Overflow

Any idea what we are missing?

--
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/61282962-bdb2-4f3c-ac6c-e002f26e2862%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Here’s my code (formatted here Bokeh confusion matrix plot bug · GitHub):


from collections import OrderedDict
import numpy as np
from bokeh.plotting import figure, show, output_file
from bokeh.models import HoverTool, ColumnDataSource
N = 20
arr2d = np.random.randint(0,10,size=(N,N))
predicted = []
actual = []
count = []
color = []
alpha = []
the_color = '#cc0000'
for col in range(N):
for rowi in range(N):
predicted.append(str(rowi))
actual.append(str(col))
count.append(arr2d[rowi,col])
a = arr2d[rowi,col]/10.0
alpha.append(a)
color.append(the_color)
source = ColumnDataSource(
data=dict(predicted=predicted, actual=actual, count=count, alphas=alpha, colors=color)
)
p = figure(title='Confusion Matrix',
x_axis_location="above", tools="resize,hover,save",
y_range=list(reversed(actual)), x_range=actual)
p.plot_width = 600
p.plot_height = p.plot_width
rectwidth = 10.9
p.rect('predicted', 'actual', rectwidth, rectwidth, source=source,
color='colors', alpha='alphas',line_width=1, line_color='k')
p.axis.major_label_text_font_size = "12pt"
p.axis.major_label_standoff = 1
p.xaxis.major_label_orientation = np.pi/3
hover = p.select(dict(type=HoverTool))
hover.tooltips = OrderedDict([
('predicted', '@predicted'),
('actual', '@actual'),
('count', '@count'),
])
show(p)

It makes this image: http://i.imgur.com/58z15Yw.png

···

On Thursday, December 10, 2015 at 12:18:31 PM UTC-5, Bryan Van de ven wrote:

Can you provide a minimal, runnable example that reproduces what you are seeing? It’s difficult to offer advice or to debug without that.

Bryan

On Dec 10, 2015, at 11:12 AM, Ryan Compton [email protected] wrote:

I’ve been trying to modify the les_mis example to use my own data (cf http://bokeh.pydata.org/en/0.10.0/docs/gallery/les_mis.html )

However, my plots are getting cut off at the min axes, eg http://i.imgur.com/KZ05gmZ.jpg

I’m not sure what’s going on and someone else recently ran into the exact same problem here: http://stackoverflow.com/questions/33936852/python-bokeh-offset-with-rect-plotting

Any idea what we are missing?


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/61282962-bdb2-4f3c-ac6c-e002f26e2862%40continuum.io.

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

Hi Ryan,

Thanks for the gist, that was perfect. The problem is this: the lists you are passing for x_range and y_range have duplicates. The values for categorical ranges need to be the unique list of *coordinates*, in the order you want them to show up. While there might be lots of data points that have, e.g. x = "a", the *range* only has one "a" coordinate. Here is a longer explanation I made on SO some time ago:

  python - Issues with Correlation graphs in Bokeh - Stack Overflow

This change fixed your example for me:

  y_range=list(reversed(list(set(actual)))), x_range=list(set(actual)))

There's probably a better way to accomplish that, but it should get you started.

I have two requests for you :slight_smile: Can you please attempt to help on the other SO issue you linked? And also can you make a GH issue for Bokeh to handle this better (most likely: issue a validation warning when the range values are not unique)

Thanks!

Bryan

···

On Dec 10, 2015, at 11:42 AM, Ryan Compton <[email protected]> wrote:

Here's my code (formatted here https://gist.github.com/rcompton/67bb614b86297c970451\):

from collections import OrderedDict

import numpy as np
from bokeh.plotting import figure, show, output_file
from bokeh.models import HoverTool, ColumnDataSource

N = 20
arr2d = np.random.randint(0,10,size=(N,N))

predicted =
actual =
count =
color =
alpha =
the_color = '#cc0000'
for col in range(N):
  for rowi in range(N):
    predicted.append(str(rowi))
    actual.append(str(col))
    count.append(arr2d[rowi,col])
    a = arr2d[rowi,col]/10.0
    alpha.append(a)
    color.append(the_color)
    
source = ColumnDataSource(
    data=dict(predicted=predicted, actual=actual, count=count, alphas=alpha, colors=color)
)

p = figure(title='Confusion Matrix',
     x_axis_location="above", tools="resize,hover,save",
     y_range=list(reversed(actual)), x_range=actual)
p.plot_width = 600
p.plot_height = p.plot_width

rectwidth = 10.9
p.rect('predicted', 'actual', rectwidth, rectwidth, source=source,
      color='colors', alpha='alphas',line_width=1, line_color='k')

p.axis.major_label_text_font_size = "12pt"
p.axis.major_label_standoff = 1
p.xaxis.major_label_orientation = np.pi/3

hover = p.select(dict(type=HoverTool))
hover.tooltips = OrderedDict([
    ('predicted', '@predicted'),
    ('actual', '@actual'),
    ('count', '@count'),
])

show(p)

It makes this image: http://i.imgur.com/58z15Yw.png

On Thursday, December 10, 2015 at 12:18:31 PM UTC-5, Bryan Van de ven wrote:
Can you provide a minimal, runnable example that reproduces what you are seeing? It's difficult to offer advice or to debug without that.

Bryan

> On Dec 10, 2015, at 11:12 AM, Ryan Compton <[email protected]> wrote:
>
> I've been trying to modify the les_mis example to use my own data (cf les_mis — Bokeh 0.10.0 documentation )
>
> However, my plots are getting cut off at the min axes, eg http://i.imgur.com/KZ05gmZ.jpg
>
> I'm not sure what's going on and someone else recently ran into the exact same problem here: matrix - python bokeh offset with rect plotting - Stack Overflow
>
> Any idea what we are missing?
>
> --
> 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/61282962-bdb2-4f3c-ac6c-e002f26e2862%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/ca6bb4dd-ba82-405c-bb18-3218f6f086c2%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Works great, many thanks.

···

On Thursday, December 10, 2015 at 12:12:37 PM UTC-5, Ryan Compton wrote:

I’ve been trying to modify the les_mis example to use my own data (cf http://bokeh.pydata.org/en/0.10.0/docs/gallery/les_mis.html )

However, my plots are getting cut off at the min axes, eg http://i.imgur.com/KZ05gmZ.jpg

I’m not sure what’s going on and someone else recently ran into the exact same problem here: http://stackoverflow.com/questions/33936852/python-bokeh-offset-with-rect-plotting

Any idea what we are missing?