Plotting business locations on maps using multiple Plotting libraries in Python

GeoPandas was able to plot all the points.

However, I found two major drawbacks here which include not having an interactive map as well as the documentation of how to use it properly is very limited.

PlotlyPlotly is yet another library that plots highly interactive charts and lets the user interact with the charts as well.

However, it requires Username and API Key to work.

You’ll have to register at https://plot.

ly/feed/#/ and get an API Key.

You’ll have to replace <USERNAME> and <API-KEY> with your own values.

We use ScatterGeo to define the points that we want to plot and can also pass their names in the text parameter.

Setting up the marker is also easy and can be modified for its size, opacity, colour etc.

The layout is used to define the plot’s title, base colour and more.

Finally, the Figure() method creates the figure which we can plot using iplot.

Plotly plot for 1000 locationsWe were able to plot 1000 points with same, but to plot them with different colors, we’ll have to have different ScatterGeo methods with different colors.

Let’s also try and plot all points.

The plot was generated after sometime, but all locations were visible though it was very laggy.

Even a warning shows up that says for plotting a large number of points, we should use other methods.

This was annoying because when I tried to return this as an image, it required the library plotly-ocra which could not be installed with pip and works only with conda.

Plotly map for all locationsBokehBokeh is an amazing visualization library that relies on Google Maps for their maps and hence, also requires an API Key we used above to work.

Given that it uses Google Maps, I highly doubt it will be able to plot all points at once.

We save the output as bokeh.


The GMapOptions helps us define the centre of map and zoom as needed.

Then we generate a gmap with these options, and also pass in the API Key.

We define the data as a ColumnDataSource as can be seen in the gist above.

Then, we plot all the points as circle on the plot and use show to display it.

It loads up the html and we can see the result, which is an interactive map.

Bokeh plot for 1000 pointsAll locations are correctly plot.

Let’s also try to plot all points.

As suspected, the page opened up with the map but was not working and was not displaying any data points either.

ResultsFrom the plots above, I identified that all libraries are really useful for plotting the data points and my observations were as follows:The easiest way to get started is with gmplot.

It requires minimal code to start and is able to produce good results too.

Plotting points with different colors based on their state was easiest in GeoPandas.

It was easy to plot all points probably because the plot is not interactive and is static.

The most interactive are Plotly plots.

They were able to produce plots with all points but were less responsive then and suggested other means of plotting.

Bokeh was able to produce really nice Google Maps plot with minimal code.

However, it also failed at plotting all points.

Hope you enjoyed reading this.

Here are a few more articles you might like:Python Virtual Environments made easyQuick guide to virtualenvtowardsdatascience.

comDeep learning to identify Malaria cells using CNN on KaggleDeep learning in Medical fieldtowardsdatascience.

comWorking with APIs using Flask, Flask RESTPlus and Swagger UIAn introduction to Flask and Flask-RESTPlustowardsdatascience.

comCreate a complete Machine learning web application using React and FlaskBuild complete ML Applications with UI and Backendtowardsdatascience.

comPlease feel free to share your thoughts, ideas and suggestions.

I’d love to hear from you.


. More details

Leave a Reply