Holoviews
INTRODUCTION:
Holoviews can be best described as a python library designed to cater data visualization way more seamless compared to low level libraries like matplotlib.It lets you focus on what you are trying to convey, instead of making you spend too much effort on writing the syntax of the process of making plots.It is built on top of already existing and popular plotting libraries like Matplotlib, Bokeh, and Plotly, allowing users to generate complex visualizations with minimal code.
1.How to install and get started?
Installing Holoviews on your computer is as easy as it gets,you can install HoloViews either with conda or pip command.
You simply have to open the terminal/command prompt on your computer and type out: “pip install holoviews”
2.Some simple features of Holoviews and Intro to basic Syntax
First of all, we need to import holoviews as hv.
Now,hv.extension(‘bokeh’)
This activates the Bokeh backend, which is a huge help in making interactive plots and we can zoom in, pan and zoom out as opposed to matplotlib where everything is static
Let’s look at a simple code to understand holoviews better
First four lines import all the necessary libraries in the jupyter notebook, numpy and pandas are necessary as they work in conjunction with holoviews and form the groundwork for using basically any library in python for data visualization.
The line:curve = hv.Curve((xs, ys))
creates a HoloViews Curve element, which represents a line plot. There are also other Holoviews elements like scatter,heatmap and points. Holoviews automatically takes care of everything and processes (xs,ys) as a structured dataset.It infers labels, axes, and scales without extra configuration. Moreover, the plot will also be interactive as we are using Bokeh in backend
On the contrary, if we use Matplotlib, the code will be way more lengthy:
3.Composing Elements[Overlay and Layout]
HoloViews provides powerful methods for combining multiple plots, enabling users to visualize relationships between different datasets efficiently. We will explore two such important features of holoviews-overlay and layout
Here is a holoviews code example demonstrating the use of Layout (‘+’)
In HoloViews, “+”” is used to compose multiple elements into a side-by-side layout, which is enormously convenient.
Now. let’s look at what’s overlay-again through a code: In this code, we use overlay (“*“) to display both related but different plots on a single axis, which helps us compare them better.It should be noted that Holoviews Overlay function automatically assigns different colors to each plot, making it convienient for us to analyze all of them simultaneously
It is also possible to generate multiple curves or scatter plots using a curve list or scatter list and then overlay all the plots together using syntax:overlay = hv.Overlay(curve_list + scatter_list)
4.Style Mapping
Holoviews offers a rich choice to customize and visually augment data in a desirable form.
Let’s look at a code which creates a customized scatter plot using HoloViews, where each point has unique properties (color, shape, transparency, and size). First line imports opts module, which allows customization of plots.
Next, we customize various parameters like shape,size,transparency and others according to our needs. Note:Lower alpha values (closer to 0) make points more transparent, while higher values (closer to 1) make them more opaque.
Now, we finally display our plot using hv.points ,hv.Points is a scatter plot element in HoloViews that represents discrete points in a 2D space. Each point can have additional visual attributes like color, size, transparency, and shape.
There are some other customizable functions worth mentioning like hv.cycle() and hv.pallette()
Example:color_cycle = hv.Cycle([‘red’, ‘green’, ‘blue’])
This line of code creates a color sequence: red → green → blue.Each dataset in the overlay will automatically receive a different color turn by turn.
5.Tabulated datasets
Let’s now look at how Holoviews handles and shows a simple data in tabulated form, again via a code Just converted this data into a table with minimal syntax.However, holoviews can even do many more meaningful visual representations.Let’s look at a few of them:
In this code, holoviews visualized the data easily using a lot of different ways including scatter plot, simple curve, area and even bar chart
6.Datasharing and how to handle large datasets
Handling large datasets is the real USP of this Python library, and this is where it distinguishes itself from libraries like Matplotlib which only work well till about 10000 data points.
Let’s look at this code to understand things better:
In this code, we generate 10 million data points randomly and spread them by a scale of 2 on both x axis and y axis.
Now, we apply the features of rasterize() and datashade(), these are essential to understand
rasterize() aggregates raw data into a fixed grid of pixels before displaying it.It Assigns a color based on density and Produces a fixed-resolution image that can be interacted with (hover, selection, etc.).
rasterize() is also faster but on the other side, it can miss a few very dense or sparse regions on the plot
On the contrary, in datashade() we dynamically render a new image each time you zoom or pan, ensuring optimal visibility.Although it makes it a bit slower compared to rasterize(), you should use it when your dataset is extremely large and extremely dense, as it can’t be optimally represented by rasterize() in that case.
7.Geometry Data
We will explore an important element in this section: the “Path” element
Unlike hv.Curve, which assumes a single continuous line, hv.Path supports multiple disconnected line segments in one element.
Lets now look at a code: What’s Happening in this code?
hv.Path([…]):
This defines a list of paths, where each path is a list of (x, y) coordinates.Each inner list represents a separate, unconnected polyline.Unlike hv.Curve, hv.Path does not assume continuity.HoloViews treats each path independently.
You can also customize the apperance of each unconnected path using hv.opts()
CONCLUSION
Now, we must answer a fundamental question:Why bother using Holoviews? Why not just Matplotlib?
To answer it, holoviews offers a streamlined approach with minimal syntax to visualize large scale data and real time geospatial data.When combined with Bokeh and Plotly in backend, it becomes an ideal choice for getting interactive plots in which you can pan, zoom in, zoom out and hover around your data to analyze it better-something that isn’t just possible in Matplotlib
While Matplotlib remains a solid choice for handling static, customizable, low-level datasets, Holoviews excels where we need to process large data sets rapidly and don’t want to waste too much time just configuring all the syntax according to our needs-Holoviews takes care of a lot of syntax automatically to lessen our work.