Data Visualization helps in analyzing hidden patterns in data that are not visible to naked human eyes. It can help in understanding the data behavior and data association. There is a wide variety of visualizations that can be used to analyze data like Bar charts, Scatter charts, etc.
Controlling visualizations can be helpful when we are trying to analyze different data points. It not only helps in controlling the data but can also be used to show how a data point is behaving with respect to other data points.
IPyWidget is an open-source Python library that is used to create widgets that can be helpful in controlling the graphs or data and make it interactive.
In this article, we will explore how to control data visualizations using widgets created using IPyWidgets.
Let’s get started…
In this article, we will create a visualization using Bokeh and create widgets using IPyWidgets. So we need to install these libraries using pip installation. The command given below will install both the libraries.
!pip install bokeh
!pip install ipywidgets
In this step, we will import all the libraries that are required for creating the visualization and widget.
import numpy as np
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, show, output_notebook
from ipywidgets import interact
Now we will create the visualization that we want to control using the widgets. Before creating visualization we need to run the Bokeh command for showing visualizations in Notebook.
output_notebook(bokeh.resources.INLINE)x = np.linspace(0, 2*np.pi, 2000)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))
p = figure(title="Bokeh example", plot_height=300, plot_width=600)
p.line('x', 'y', source=source, color="#2222aa", line_width=3)
Now we will start with creating the widget that we will use to control the visualization that we created above.
def update(f, w=2, A=1, phi=0):
if f == "sin": func = np.sin
elif f == "cos": func = np.cos
elif f == "tan": func = np.tan
source.data['y'] = A * func(w * x + phi)
bokeh.io.push_notebook()_ = interact(update, f=["sin", "cos", "tan"], w=(0,100), A=(1,10), phi=(0, 10, 0.1))
Now we will use this widget to control the visualization we have created above.
Here you can clearly visualize different how we can control the visualization we have created. Go ahead…
Continue reading: https://towardsdatascience.com/connecting-widgets-to-visualizations-dc668bbeaeb?source=rss—-7f60cf5620c9—4