bqplot: Bringing more interactivity to data

Dhruv Madeka, a quantitative researcher at Bloomberg, describes the open source library D3 (or D3.js), which is used to make interactive data visualizations, as “awesome.” But for many would-be fans, it has one major shortfall: You need to know JavaScript in order to use it. And most data scientists, academics and others who work in data analysis or machine learning prefer Python.

In 2014, the Quantitative Research team at Bloomberg began a project to build a Python front-end for D3. As the team continued its work, they realized that they needed an easier and more structured way to let users build complex interactions than D3 allowed, so their project started to increase in scope. Eventually, they developed the interactive plotting library bqplot.

bqplot allows anyone to build fully interactive web applications in Python, using surprisingly few lines of code. With about a dozen lines of code, for example, bqplot can generate a map of U.S. electoral results by county. Use a mouse to hover over any particular county and you’ll get a tooltip with the name of the county and the percentage of the vote in that county that went to a particular party or candidate, or a chart showing the historical vote breakdown for that county.

bqplot includes routine plots that are familiar to anyone who works in data visualization, as well as interactive selections, candle plots and other novel visualizations that are especially well-suited to financial data. For example, Bloomberg’s team developed an original, finance-inspired visualization called a market map. bqplot is currently written for the Jupyter Notebook. He expects it will be the first plotting library to fully leverage the upcoming JupyterLab platform. And because bqplot is based on the data visualization theories set out in the Grammar of Graphics, users can easily build complex interactive visualizations.

“We are the first large-scale project that doesn’t require you to write any JavaScript code to create and present these interactive applications,” says Madeka. “That makes it much easier for data scientists, academics and business users to understand their data and educate their audiences.”

Srinivas Kumar Sunkara, another quantitative researcher at Bloomberg, will be presenting bqplot at PLOTCON 2017 in Oakland, California, on May 4. In July, Project Jupyter contributors Sylvain Corlay and Jason Grout will lead a SciPy tutorial on interactivity in the Jupyter Notebook and bqplot in Austin. Earlier this year, Madeka presented bqplot at PyData Ann Arbor and the D3.js Meetup in New York City.

Why Data Analysis and Interactivity Belong Together

From the beginning, the developers of bqplot put a priority on interactivity. As Srinivas puts it: ”Some plotting libraries try to optimize on the number of points to be displayed. We optimize on the interactivity of each point.”

Each attribute in a chart made with bqplot is actually an interactive widget that can be bound to a Python function. That means that users who are playing with the plots can use changes in those elements to trigger other functions, which can adjust the plot in a myriad of ways. The widgets also enable the creation of full-scale web apps using bqplot.

As data visualization becomes a more significant element of data analysis, being able to easily interact with large quantities of data becomes more important. Using bqplot, someone working with multiple variables can plot their data easily, and then click on the outliers to get more information. While the basic plotting in the electoral vote map above provided simple tooltips that only display vote counts, bqplot’s functionality can be used to provide more in-depth information about a particular point, such as a radar chart of all the inputs behind it.

Researchers can also use bqplot to select certain variables visually, and understand the effect of including and excluding them. “We have a lot more data now,” says Sunkara. ”You want to understand your data a little better before you throw it into a black box and expect an algorithm to work.”

Bloomberg published the first version of bqplot in October 2015, and the plotting library already has its share of fans. Among them are Bloomberg researchers who use it to prototype new functions; biologists and physicists working with complicated data sets; and, because bqplot makes it uniquely easy to understand how a function responds to a change in input, university professors who use it as an interactive tool for teaching.

”It lowers a barrier of entry,” shares Dhruv, “because the plotting is easy to do. You can be mainly concerned with the particular scientific function you’re trying to explore and understand.” To most researchers and data scientists, that sounds like a lot more fun than learning JavaScript.

If you’re interested in joining our team to work on bqplot and other tools in the Jupyter ecosystem, click here.