Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I am trying to plot a custom lollipop chart by using a python script. Please see below:
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.
Solved! Go to 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
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.
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:
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
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.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 61 | |
| 44 | |
| 41 | |
| 36 | |
| 21 |
| User | Count |
|---|---|
| 176 | |
| 120 | |
| 106 | |
| 77 | |
| 52 |