RUVIDEO
Поделитесь видео 🙏

Python Tutorial: Customizing glyphs

Want to learn more? Take the full course at https://learn.datacamp.com/courses/interactive-data-visualization-with-bokeh at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.

---
We've seen how to create and use glyphs, and specify their basic visual properties. Sometimes, it's useful to be able to alter the appearance of a glyph, for instance when a user makes a selection, or hovers over our glyphs. Let's see how the visual appearance of glyphs can be altered in these situations. Bokeh has several different tools to enable users to select points on a plot using mouse or touch interactions. In this example we create a figure that specifies "tools='box_select,lasso_select'". This configures our plot to have two different kinds of select tools. A "box select" tool that allows you to select points by dragging a rectangular region over the plot. And a "lasso select" tool that allows points to be selected by drawing a free form curve. When points are selected using one of Bokeh's selection tools, how is this fact made visually evident? By default, once a selection is made, Bokeh draws all the NON-selected points with a very low transparency (or alpha value). However it is possible to customize this behavior. To do so we simply pass additional arguments to the glyph method. These arguments are the same visual properties we have already seen, such as "fill_color", except that they either have the prefix "selection_" or "nonselection_".

Let's take a look at the call to "circle" in this example. Here, we specify "selection_color=red". This configures the plot so that whenever a selection is active, all the selected points have a fill_color of red. Note that an argument "color" is just shorthand for specifying "fill_color" and line_color at the same time. Additionally, we specify "nonselection_fill_alpha=0.2" and "nonselection_fill_color=grey". These two arguments configure the plots so that whenever there is a selection made, all the NON selected points will be shaded grey, with a high transparency. The two plots here show the effects before and after a selection. Before the selection, all the circles are drawn with a default appearance. After a selection is made with the box select tool, the unselected points outside the box are grey and transparent, and the selected points inside the box are all shaded red.

It's also possible to add a Hover Tool to bokeh plots. The hover tool can be used to drive hover tooltips (we will see later) but can also be used to inform changes to the visual appearance of glyphs. The hover tool is a bit more sophisticated, let's first take a look at how it is added in this example.

First we import HoverTool from bokeh.models. We create a hover tool instance called "hover" by calling the HoverTool initalizer. we pass in the arguments tooltips=None, and mode="hline". This configures the hover tool not to display any tooltips, and to use a horizontal line under the current mouse position to perform hover inspections. We add this tool, as well as a crosshair tool to our plot by passing a list containing the hover tool, and the string name "crosshair" as the tools argument to figure. Having added our hover tool, we can now also specify a hover policy. This is very similar to the how selection policies are specified. Instead of property names prefixed with "selection", we can add property names prefixed with "hover". In this example we have added "hover_color=red" to our call to circle. Accordingly whenever a circle is hovered, it is drawn as red. All other circles are drawn in their normal fashion.

Finally we look at one more important way to customize visual appearance which has to do with shading groups of data differently. Let's consider the iris data, which has data for three different species of flower. What if we want to shade each species differently? We could make three separate calls to "circle" each with a subset of the data, and a different single color. Or we could make single call to circle, with a column of colors that we compute based on species.

But there is often a better way, which is to configure the color properties by using a colormapper. A colormapper can automatically transform the values of some column of data into colors. Let's take a closer look.

First we need to create a CategoricalColormapper. In this example we import it from bokeh.models. The color mapper needs to be configured with two arguments. The first is a list of the values to map. In this case, it is the three species names in the data: [setosa, virginica, versicolor]. Next we also have to supply a palette, which is just a list of colors. We provide an explicit list [red, green, blue] here, but there are many built in palettes available in bokeh.palettes that can be used as well.

#PythonTutorial #Python #DataCamp #Interactive #Data #Visualization #Bokeh #glyphs

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Python Tutorial: Customizing glyphs», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.