[bokeh] patches creation hard to understand - how to return custom x range?

Hi Thomas,

The patch (or patches) glyph plot polygons. So they can be used to show things like tolerance bands. But you will have to compute the coordinates of the polygon that represents your tolerance band. The reason you need to "reverse" the x coordinates is because polygon coordinates need to form a closed path, and you have to have as many x coordinates as y coordinates Something like:

x -> [0, 1, 2, 3, 3, 2, 1, 1]
y -> [5, 6, 6, 7, 2, 1, 3, 1]

Yes this should be made simpler with the addition of some helper or utility functions that can compute the polygon coords for you, given a path and a tolerance. Things can get a bit more complicated if the resolution of the error results don't exactly match up with the initial path coordinates, etc. Pull requests welcome!!

Thanks

Bryan

···

On May 27, 2014, at 3:22 AM, Thomas Rusche <[email protected]> wrote:

Hey,

how can you make a tolerance band around a graph?
My custom graph is a sinus curve from 0 to 2*pi (=12 round about)
I customized the brewer example from here: http://bokeh.pydata.org/docs/gallery/brewer.html
However the patches return not the same x range.
Where does the x2 come from? It is a fix name for whatever and comes out off nowwhere.
And why do I need to reverse one x-range?

However, how can I fit the patches to my curve? To check what the program does, i printed x2 and the list of areavalues.
The structure seems hard to understand, can't this be done in a more simple way?

from collections import OrderedDict
import numpy as np
import pandas as pd
from bokeh.plotting import *

N = 100
pi = 3.14159
x = np.linspace(0,4*pi,N)
print x
y = np.sin(x)
line(x,y,color="black")

output_file("sinus_tolerances.html")

def markupToleranceArea(x, y, tolerance):
    data = {}
    N = len(y)
    
    data['x'] = x
    data['y'] = y
    data['yLowerTol'] = y * (1-tolerance)
    data['yUpperTol'] = y * (1+tolerance)
    
    areas = OrderedDict()
    markupFrom = data['yLowerTol'][::-1]
    markupTo = data['yUpperTol']
    areas['markedUp'] = np.hstack((markupFrom, markupTo))
    print len(areas['markedUp'])
    
    for a in areas:
        print x2
        print list(areas.values())
        
    hold(True)
    line(x,y,color="black") #Graph, from which the tolerance should be plotted.
    patches([x2 for a in areas], list(areas.values()), color="lightgrey", alpha=0.5, line_color="grey")
    hold(False)
    return areas

areas = markupToleranceArea(x,y,0.05)

show()

--
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/f21e64ff-3774-4ff4-b594-609f423e46fc%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

I am similarly having some difficulty understanding how to effectively use the patches plotting for a task I am attempting. I have two main issues:

  1. Is it possible to have holes in the patches, such as in the matplotlib.path.Path() object [info at http://matplotlib.org/api/path_api.html]. I am trying to use the patches to plot boundaries of information from shape files (such as geographical features, and country borders). In my case, I essentially need holes in the patches which represent islands within lakes.

  2. The hover tool is very useful, however I am having an issue where I have plotted two types of patches (i.e. polygons). One type are country boundaries (for these I do not want a hover message to appear as they are there only for a visual aid). The second type of patches are lakes, these need metadata with the hover tool. I can not find a way to suppress the hover tool for the country patches. Any ideas how I can do this?

For further context, the beginnings of the figure I am trying to create is here (the final figure will have many many more lakes…): http://www.files.benlaken.com/documents/Lake_test.html

It is about 7mb, if you zoom on some of the dark points, you will see they are patches to represent lakes, and you will similarly see metadata over the lakes with the hover tool. But again, 1) many of the lakes need holes for islands, and 2) I need to suppress the hover tool when not over lakes. Any ideas if/how this can be done?

Thanks!