Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Python matplotlib shows nothing when using dataset, works with lists

I have a simple dataset that looks like this:

year votes
1999 100
2000 150
2001 200

Trying to plot a simple line chart like this:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()

ax.plot(dataset.year, dataset.votes)

ax.set_xlim(1998, 2002)
ax.set_ylim(90, 210)
plt.show()

Gives me this result (i.e. nothing is plotted but Python/Power BI give me no errors).

image.png

Specifying the same data in lists and then plot them like this works:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()

year_array= [1999,2000,2001]
votes_array = [100,150,200]

ax.plot(year_array, votes_array)

ax.set_xlim(1998, 2002)
ax.set_ylim(90, 210)
plt.show()

Result:

image.png

Am I doing something wrong? The data is formatted as Numbers so the problem is not that. I am using Python 3.6.5 Anaconda distribution and Power BI 2.61.5192.601 64-bit (August 2018) on a Windows 10 machine.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

My colleague found what the problem was. The values were summed when dragged in to the value field, i chose "Don't Summarize" and now it works like a charm.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

My colleague found what the problem was. The values were summed when dragged in to the value field, i chose "Don't Summarize" and now it works like a charm.

v-frfei-msft
Community Support
Community Support

Hi @Anonymous,

 

Based on my test, When I used the code as below. It worked well as well. Did you add the both columns to the Python visual and enter the code?

 

import matplotlib.pyplot as plt
fig, ax = plt.subplots()

ax.plot(dataset.year, dataset.votes)

ax.set_xlim(1998, 2002)
ax.set_ylim(90, 210)
plt.show()

FC2EC784.PNG

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Yes I did, i reckon I would have gotten `KeyError` otherwise and I got no error now. I will try on a collegaues computer and also try uninstalling and installing Power BI otherwise. Python seems to working fine outside of Power BI Python visuals so I assume there is something wrong with Power BI.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.