Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. 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()
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
84 | |
75 | |
68 | |
41 | |
35 |
User | Count |
---|---|
107 | |
56 | |
52 | |
48 | |
40 |