Python Tutorial: Additional glyphs

Learn how Bokeh renders glyphs beyond markers. The instructor shows line() for line glyphs, layering multiple glyphs by calling methods in sequence, and patches() for drawing polygonal shapes like geographic regions using list-of-lists coordinate structures.
Chapters
In addition to marker like glyphs such as circles or squares, Bokeh can draw many other kinds of visual shapes. Let's take a look at some of them. Lines are a graphical component that is important in many different situations. With Bokeh, lines are created using the dot line method in exactly the same way that we saw in the last section. Now, instead of drawing circles or other markers at the X and Y coordinates, a line is drawn through those coordinates. If you'd like to have markers and lines together, Bokeh makes it simple to combine multiple glyphs on one plot. Simply call more than one glyph method. All the glyphs that you specify will be drawn in the order of the glyph methods that you call. In the example here, we see that line has been called first and then next circle has been called with fillcolor white. Accordingly, we see a line with filled circles drawn on top. In this case, we used the same data values for both glyphs, but that is not required. Any combination of glyphs using any combination of data as inputs will always work. Another useful glyph is patches. Patches can be used to draw multiple polygonal shapes at once on a single plot. This might be useful if you want to draw geographic regions such as countries or states. The input data for patches takes a slightly different form, which is worth looking into. Just like circle can draw multiple circles by being provided a list of coordinates, patches can draw multiple polygons by being given a list of patch coordinates. But each patch itself needs multiple coordinates. For this reason, the coordinate data for dot patches is a list of lists. One list of lists is for the X coordinates, the other for the Y coordinates. Each sub list contains the X or Y coordinates for one patch, and the corresponding sub list for each individual patch must match in length. In the example here, we can see the lists Xs and Ys, which are both of length 3. This data corresponds to the three patches being drawn, but each of the three items in the list is another list with all of the X coordinates or Y coordinates for one of the three patches, it's only the coordinates that are nested in this way. If we want to shade each of the three patches from the previous slide in a different color, we can pass, for instance Fill color red, blue, green, a list of three colors because there are three patches, although we won't practice with them directly in this course. I also wanted to mention there are other glyphs that are available in Bokeh. Glyphs like Wedge, Annular, Wedge, Rect, VBAR hbar, and others can be used to create extremely versatile visualizations for all kinds of data. For more information, see bokeh.pidata.org.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







