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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
HamidBee
Power Participant
Power Participant

Python Lollipop Chart not displaying

I am trying to plot a custom lollipop chart by using a python script. Please see below:

 

Python.png

For some reason it doens't seem to work. I am attaching the pbix file below:

 

https://www.mediafire.com/file/5rqvuc2s96zdsxg/Python.pbix/file

 

Thanks in advance.

1 ACCEPTED SOLUTION

Hi @HamidBee ,

 

These are some thing about python.

1 function chr():

Return the string representing a character whose Unicode code point is the integer.

2 size:

the shape or the number of the matrix which generated by np.random.uniform. In your case the shape is 1*20, it will generate 20 floating point numbers

vchenwuzmsft_0-1640745517094.png

3 random means the numbers generated are not regular, they are random.

4 For the X axis:

 

plt.xticks( my_range, ordered_df['group'])

 

The code above is used to set the X axis as the ordered_df['group']. in another word, the plt.xticks is used  to substitute X axis, from my_range to ordered_df['group'].

5 Please try  this code:

 

import matplotlib.pyplot as plt

# # Make the plot
plt.stem(dataset['Month'],dataset['Total B'])
plt.show()

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-chenwuz-msft
Community Support
Community Support

Hi @HamidBee ,

 

python code some thing wrong. you can click the "see details" if you want know the error.

 

I have editor your code and get the image from python script successfully, please refer this:

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df = pd.DataFrame({'group':list(map(chr, range(65, 85))), 'values':np.random.uniform(size=20) })

# # Reorder it following the values:
ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)

# # Make the plot
plt.stem(dataset['Total B'])
plt.xticks( my_range, ordered_df['group'])

plt.show()

result:

vchenwuzmsft_0-1640584455878.png

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thank you. I would like to ask though why it doesn't seem to display the months along the axis. Also, is it possible to please explain what the following do:

 

'group':list(map(chr, range(65, 85)))

Is 65 and 85 supposed to be numbers? Also is this for the x axis?

 

'values':np.random.uniform(size=20)

Also what is meant by size and random?

ordered_df = df.sort_values(by='values')
my_range=range(1,len(df.index)+1)

Thanks in advance.

Hi @HamidBee ,

 

These are some thing about python.

1 function chr():

Return the string representing a character whose Unicode code point is the integer.

2 size:

the shape or the number of the matrix which generated by np.random.uniform. In your case the shape is 1*20, it will generate 20 floating point numbers

vchenwuzmsft_0-1640745517094.png

3 random means the numbers generated are not regular, they are random.

4 For the X axis:

 

plt.xticks( my_range, ordered_df['group'])

 

The code above is used to set the X axis as the ordered_df['group']. in another word, the plt.xticks is used  to substitute X axis, from my_range to ordered_df['group'].

5 Please try  this code:

 

import matplotlib.pyplot as plt

# # Make the plot
plt.stem(dataset['Month'],dataset['Total B'])
plt.show()

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.