Visualize Tesla Supercharging stations with MySQL and Plotly

Plotly Database Connector is a cross-platform application that connects your databases to Plotly 2.0.

Using this, you can directly import the necessary data from your database and plot it on the fly.

In this post, we will plot the Tesla supercharging stations on the world map. We will use a MySQL database containing this data.

Download the Plotly Database Connector App

You can download the latest application release for both Windows and Mac, or there are more options on GitHub for advanced users.

db_cnx_download
Download the app

If you are on Windows, make sure the application folder is in your C:/Program Files folder.
Launch the application by executing it. You may need to start the application as an administrator.

Launch the application
Launch the application

 

Go for the Open Session option.

Setup the MySQL database

We are using MySQL for this post, you are free to choose from a number of databases. You can vote for your favorite database if it’s not in the list.

Download the SQL schema file (tesla.sql) that contains the details of Tesla supercharger stations.

Login to your MySQL service with the suitable user (root for this post).

Enter the password for user root, when asked.

Create a database named tesla and select it, as explained below.

Source the schema file to populate the database. It will create a table named superchargers in the database tesla, and insert the data rows.

It will take some time to insert all the rows.

Connect to the database

Select the database type in the application, MySQL is selected by default.

Fill in the credentials and press the Connect button.

Connect to the database
Connect to the database

 

We can leave the host and password fields, because it will automatically use the default values for local MySQL service.

Once connected, we can preview the database content in the application.

Preview database and tables
Preview database and tables

Query the database

Go to the Plotly 2.0, and click on the Import button in the top-right area.

Select the SQL option and press Connect.

Connect from Plotly 2.0
Connect from Plotly 2.0

 

Database Connector runs on plain HTTP protocol as of now, you must follow insecure connections in order to use it.

Just make sure your browser’s safe scripting setting is turned off. While using Chrome Browser, you will have to load unsafe scripts.

Once connected, you can see a SQL Editor. Select the appropriate database and run any query of your choice.

Query the database from Plotly 2.0
Query the database from Plotly 2.0

Plot the supercharging stations

Once we have connected the database with Plotly 2.0, visualizing the data is just the matter of correct database queries and selecting chart attributes according to the query result.

For example, we will query the geographic details (latitude, longitude, and location columns) to plot all the supercharging station around the world.

We are going to use Atlas Maps as the Chart type.

As you can see in the left panel, here are the chart attributes we have selected for the plot.

  • Latitude – latitude
  • Longitude – longitude
  • Hover Text – location
Atlas Map of Tesla Supercharging Stations around the world
Atlas Map of Tesla Supercharging Stations around the world

You can see the chart preview as you change the attributes. Options are available to save and share the chart.

Here is the resultant map, embedded in the post.

Satellite map of tesla supercharging stations

Plotly also supports Satellite Maps using Mapbox.

Plotly - Satellite Map Support
Plotly – Satellite Map Support

 

Here is the satellite map using the same data.

Charging station distribution per country

Type the following query in the SQL Editor. It will collect the no. of stations per country.

Select the chart attributes as shown below.

Attributes for Charging Station Distribution (per country) Chart
Attributes for Charging Station Distribution (per country) Chart

Geographic distribution of Supercharging stations

Using the same query, we can generate a Choropleth map to show the geographic distribution of stations per country.

Similarly, you can use Plotly Database Connector to plot your database content easily.