Don't miss your chance to take exam DP-600 or DP-700 on us!
Request nowLearn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
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()
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 51 | |
| 40 | |
| 37 | |
| 14 | |
| 14 |
| User | Count |
|---|---|
| 85 | |
| 69 | |
| 38 | |
| 29 | |
| 27 |