Creating a box plot using Python in Power BI

You are currently viewing Creating a box plot using Python in Power BI
We have recently included python in our Power BI Advanced online and onsite training course due to its increasing popularity. Python is by far the most widely used programming language for machine learning and deep learning models. A lot of developers use python’s visualization libraries for creating visualization plots. In this blog post, python has been used to create box plot in Power BI desktop. Before getting your hands on the fancy plots, we recommend our readers to go through the following introductory blogs based on their level of expertise in python. Visualization is important to understand the data before the development can be started. A good visualization can convey one thousand words in just one graph. Visuals help to analyze and give quick insights about the dataset. This helps to make more effective and efficient business decisions. Therefore, visualization is very important to catch patterns in the data and then decide the path of development for your machine learning model. Even once the model is ready, data visualization plays an important part in hyper parameter tuning and tweaking the variables to get a better accuracy.  It uncovers the variables which should be the focus of development. Python has large number of visualization libraries. In order to create visuals, follow the below mentioned steps:
  1. Select Visualization Tab under the Visualizations Pane
Power BI Online and Onsite Training in Australia 5

2. Click on Python Visual. The following window will appear.

Power BI Online and Onsite Training in Australia 4

3. Click on Enable to enable Python Scripts. The following window will appear.

Power BI Online and Onsite Training in Australia 3

Python script editor automatically creates the dataset using the library Pandas. It creates the data frame with required column fields.

4. Now to start scripting, drag and drop fields into the Visualizations pane. Or you may also check the checkboxes for adding them into the script editor.

Creating a Box Plot

A Boxplot gives a summary of your data. It depicts if your data is symmetrical and highlights the outliers. It also indicates how your data is distributed in the dataset. 

 1. In the editor, write the Python code as shown below to draw a box plot.

We will be using pre built library functions from matplotlib.pyplot. Matplotlib.pyplot is drawing a line graph of all the four dimensions independently.

2. Now, run script by clicking at play button at the top right corner of the screen.

Power BI Online and Onsite Training in Australia 2

In the box plot, all four dimensions (i.e the sepal width, petal width, sepal length, petal length) are examined independently. It indicates how values in each dimension are spread out. For example, let’s explain the sepal width dimension. The visual indicates that the min value is 2 and the max is 4.4. 25% of data is lower than 2.8 and 75% is above 2.8.

3. The plot of the dataset will be generated accordingly.

Power BI Online and Onsite Training in Australia 1


Box plot is one of the most recommended visuals for exploratory data analysis. It is also known as box and whisker plot and displays the data distribution using the data quartiles. Box plot can be created in Power BI using some python libraries such as Matplotlib and Pyplot. This blog posts presents a step-by-step guide to creating a box plot in Power BI desktop using python.

More Checkouts for Power BI Training in Australia.

Leave a Reply