Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi All,
I'm trying to create a line chart in Python Visual with the following;
| X-axis | Legend | Measure |
| 0,808333 | Dim1 | 291 |
| 8,522222 | Dim2 | 295 |
| 13,74167 | Dim1 | 291 |
| 28,32222 | Dim2 | 297 |
The result be like this
I'm struggling to get that second line in by the column "Legend"
The code I have;
from matplotlib import pyplot as plt
import pandas as pd
#ax = plt.gca()
f, ax = plt.subplots()
line1 = dataset.plot('X-axis', 'Measure', color="#333333")
line2 = dataset.plot('X-axis', 'Measure', color="#999999")
plt.show()
Solved! Go to Solution.
Here is the simplest implementation, hardcoding your legend values.
ax = matplotlib.pyplot.gca()
dataset.query('Legend == "Dim1"').plot(x='X-axis', y='Measure',color='green', ax=ax, label='Dim1')
dataset.query('Legend == "Dim2"').plot(x='X-axis', y='Measure',color='red', ax=ax, label='Dim2')
matplotlib.pyplot.show()
Here is the simplest implementation, hardcoding your legend values.
ax = matplotlib.pyplot.gca()
dataset.query('Legend == "Dim1"').plot(x='X-axis', y='Measure',color='green', ax=ax, label='Dim1')
dataset.query('Legend == "Dim2"').plot(x='X-axis', y='Measure',color='red', ax=ax, label='Dim2')
matplotlib.pyplot.show()
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 66 | |
| 44 | |
| 40 | |
| 29 | |
| 19 |
| User | Count |
|---|---|
| 200 | |
| 126 | |
| 103 | |
| 70 | |
| 53 |