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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.