👀
Crash Visualization
  • Welcome
  • Preface
    • Who the book is written for
    • How the book is organized
  • 1. Introduction of Data Visualization
    • 1.1 What is data visualization?
    • 1.2 Why does visualization matter?
  • 2. Tricks in Visualization
    • 2.1 Choose Appropriate Chart
    • 2.2 Features of Charts
      • 2.2.1 Table
      • 2.2.2 Column Chart
      • 2.2.3 Line Chart
      • 2.2.4 Pie Chart
      • 2.2.5 Scatter Chart
      • 2.2.6 Map Chart
    • 2.3 Misused Graph
    • 2.4 Tips in Visualization
  • 3. Matplotlib
    • 3.1 Basic Concepts
    • 3.2 Line Chart
    • 3.3 Area Chart
    • 3.4 Column Chart
    • 3.5 Histogram Chart
    • 3.6 Scatter Chart
    • 3.7 Lollipop Chart
    • 3.8 Pie Chart
    • 3.9 Venn Chart
    • 3.10 Waffle Chart
    • 3.11 Animation
  • 4. Seaborn
    • 4.1 Trends
    • 4.2 Ranking
      • 4.2.1 Barplot
      • 4.2.2 Boxplot
    • 4.3 Composition
      • 4.3.1 Stacked Chart
    • 4.4 Correlation
      • 4.4.1 Scatter Plot
      • 4.4.2 Linear Relationship
      • 4.4.3 Heatmap
      • 4.4.4 Pairplot
    • 4.5 Distribution
      • 4.5.1 Boxplot
      • 4.5.2 Violin plot
      • 4.5.3 Histogram plot
      • 4.5.4 Density plot
      • 4.5.5 Joint plot
  • 5. Bokeh
    • 5.1 Basic Plotting
    • 5.2 Data Sources
    • 5.3 Annotations
    • 5.4 Categorical Data
    • 5.5 Presentation and Layouts
    • 5.6 Linking and Interactions
    • 5.7 Network Graph
    • 5.8 Widgets
  • 6. Plotly
    • 6.1 Fundamental Concepts
      • 6.1.1 Plotly Express
      • 6.1.2 Plotly Graph Objects
    • 6.2 Advanced Charts
      • 6.2.1 Advanced Scatter Chart
      • 6.2.2 Advanced Bar Chart
      • 6.2.3 Advanced Pie Chart
      • 6.2.4 Advanced Heatmap
      • 6.2.5 Sankey Chart
      • 6.2.6 Tables
    • 6.3 Statistical Charts
      • 6.3.1 Common Statistical Charts
      • 6.3.2 Dendrograms
      • 6.3.3 Radar Chart
      • 6.3.4 Polar Chart
      • 6.3.5 Streamline Chart
    • 6.4 Financial Charts
      • 6.4.1 Funnel Chart
      • 6.4.2 Candlestick Chart
      • 6.4.3 Waterfall Chart
  • Support
    • Donation
Powered by GitBook
On this page
  • 1. Linked Panning
  • 2. Linked Brushing
  • 3. Linked Properties
  • 4.Hiding Glyphs

Was this helpful?

  1. 5. Bokeh

5.6 Linking and Interactions

1. Linked Panning

It’s often useful to link plots to add connected interactivity between plots. We can link pan or zooming actions across plots. All that is needed to enable this feature is to share range objects between figure() calls.

Let's prepare some data firstly

x = list(range(11))
y0 = x
y1 = [xx*(-1) for xx in x]
y2 = [xx**2 for xx in x]
# create a new plot
s1 = figure(plot_width=300, plot_height=300, title=None)
s1.circle(x, y0, size=20, color="forestgreen", alpha=0.5)
# create a new plot and share both ranges
s2 = figure(plot_width=300, plot_height=300, x_range=s1.x_range, y_range=s1.y_range, title=None)
s2.diamond(x, y1, size=20, color="dodgerblue", alpha=0.5)

# create a new plot and share only one range
s3 = figure(plot_width=300, plot_height=300, x_range=s1.x_range, title=None)
s3.square(x, y2, size=20, color="orange", alpha=0.5)

p = gridplot([[s1, s2, s3]], toolbar_location=None)
show(p)

2. Linked Brushing

Linked brushing is expressed by sharing data sources between glyph renderers. This is all needs to understand that selections acted on one glyph must pass to all other glyphs that share that same source.

TOOLS = "box_select,lasso_select,help"
# the rest are similar,  only we add  "tools  = TOOLS" here.
s1 = figure(tools=TOOLS, plot_width=300, plot_height=300, title=None)
s1.circle(x, y0, size=20, color="forestgreen")

3. Linked Properties

It is also possible to link values of Bokeh model properties together so that they remain synchronized. We need to use the js_link method.

rom bokeh.models import Slider   # Slide is a widget
plot = figure(plot_width=400, plot_height=400)
r = plot.circle([1,2,3,4,5,], [4,3,5,6,5], radius=0.2, alpha=0.5,color = 'deeppink')

#  create a slider
slider = Slider(start=0.5, end=2, step=0.05, value=0.5)

# link with js_link function
slider.js_link('value', r.glyph, 'radius')

show(column(plot, slider))

4.Hiding Glyphs

Sometimes it is valuable to be able to hide or mute glyphs by clicking on an entry in a Legend. Thus, your audience can pay more attention to what you want them to focus on. Let's use the stock graph for example.

import pandas as pd
from bokeh.sampledata.stocks import AAPL, GOOG, IBM

p = figure(plot_width=900, plot_height=300, x_axis_type="datetime")
p.title.text = 'Click on legend entries to hide the corresponding lines'
colors = ['orange','deeppink','royalblue']

for data, name, color in zip([AAPL, IBM, GOOG], ["AAPL","IBM", "GOOG"], colors):
    df = pd.DataFrame(data)
    df['date'] = pd.to_datetime(df['date'])
    p.line(df['date'], df['close'], line_width=3, color=color, alpha=0.7, legend_label=name)

p.legend.location = "top_left"
p.legend.click_policy="hide"

show(p)

Previous5.5 Presentation and LayoutsNext5.7 Network Graph

Last updated 4 years ago

Was this helpful?