Get startedGet started for free

Customizing glyph settings

1. Customizing glyph settings

Welcome to the third chapter of the course. In this video, we will discuss how and when to customize glyph settings, including size, color, and transparency. Adjusting glyph settings is a great way to improve the aesthetics of our plot and draw attention to specific elements. Let’s get started!

2. Glyph size

The first glyph setting we can modify is the size, in pixels, taken up by each observation. If we have a lower number of observations in our dataset, or the data is spread out, we can increase the size to improve aesthetics. Or, if we have lots of observations close together, we can decrease size to minimize overlap. By default, glyph size is set to four pixels. We can edit this by using the size argument when adding glyphs to a figure. The example shows a plot where each circle glyph is twelve pixels in size.

3. Glyph outline color

By default, Bokeh will render glyphs in blue. We have the ability to customize the color of each glyph's outline. This can help make observations stand out when they are close together, as well as adding contrast to our plot. We can use the line_color argument when adding glyphs to change the glyph's outline color to red while keeping the inside blue.

4. Glyph fill color

We previously used the color argument to modify glyph colors. If we would like to keep the perimeter color to the default of blue and modify the color inside the glyph, we can use the fill_color argument. To do this, we pass a string to fill_color when adding glyphs. As an example, we generate red glyphs but keep the default blue color around the perimeter.

5. Glyph transparency

If we have lots of overlapping observations, rather than changing the color or size, we could edit the transparency of our glyphs. This makes it easier for stakeholders to see all observations, and by extension, to draw insights. We do this by including the fill_alpha argument when adding glyphs, passing a decimal value to determine the level of transparency. The default is one-point-zero, which produces glyphs without any transparency. Here we use zero-point-two for both sets of glyphs. Where the observations are heavily clustered, it can still be difficult to distinguish between observations, but where there is some overlap, we can now clearly see each glyph.

6. Updating glyphs

What if we have created a plot and then need to modify some of the glyph settings to enhance the visualization? To do this, rather than just calling fig-dot-circle, we store the call as a variable. In this case, we call it circle. We can then access the variable's attributes to make changes. We assign twenty to circle-dot-glyph-dot-size to increase glyph size and orange to circle-dot-glyph-dot-fill_color to change the color.

7. Line glyphs

We have discussed methods for modifying glyphs in scatter plots, but some of these can also be applied to line glyphs by using slightly different arguments. We use line_width to set the size of the line, alpha to specify the level of the line's transparency, and line_color to change the color of the line. There is no equivalent for setting the color only inside the line or around its perimeter.

8. The dataset

For the first half of this chapter, we will be working with the sports media agency again. As a reminder, here are the first three rows of the nba dataset, printed across two outputs.

9. Let's practice!

Now let's put our glyph modification skills into practice!