nerdexam
Microsoft

DP-500 · Question #55

You are creating a Power BI Desktop report. You add a Python visual to the report page. You plan to create a scatter chart to visualize the data. You add Python code to the Python script editor. You…

This question tests your ability to write Python code within Power BI Desktop's Python visual to create a scatter chart using matplotlib, which is the supported visualization library for Python visuals in Power BI.

Explore and visualize data

Question

You are creating a Power BI Desktop report. You add a Python visual to the report page. You plan to create a scatter chart to visualize the data. You add Python code to the Python script editor. You need to create the scatter chart. How should you complete the Python code? To answer, select the appropriate options in the answer area. NOTE: Each correct selection is worth one point.

Explanation

This question tests your ability to write Python code within Power BI Desktop's Python visual to create a scatter chart using matplotlib, which is the supported visualization library for Python visuals in Power BI.

Approach. In Power BI's Python visual, the dataset passed from Power BI is available as a pandas DataFrame called 'dataset'. To create a scatter chart, you use matplotlib.pyplot - typically imported as 'plt' - and call plt.scatter(dataset['ColumnX'], dataset['ColumnY']) to plot the data points. You must end the script with plt.show() so Power BI can render the resulting figure. The complete minimal pattern is: import matplotlib.pyplot as plt, then plt.scatter(x_column, y_column), then plt.show().

Concept tested. Writing Python visualization code inside Power BI Desktop's Python script editor, specifically: (1) understanding that Power BI exposes selected fields as a pandas DataFrame named 'dataset', (2) using matplotlib.pyplot for rendering, (3) using plt.scatter() for scatter charts, and (4) calling plt.show() to trigger rendering in the visual pane.

Reference. Microsoft Learn - Create Power BI visuals using Python: https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-python-visuals

Topics

#Power BI Python visual#Python data visualization#Scatter chart#Matplotlib

Community Discussion

No community discussion yet for this question.

Full DP-500 Practice