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.
Good afternoon, PBI DT community.
I have a Python script (see code below) that is supposed to return the visual listed below but instead it returns an error: Must Python in Power Bi use fields from a Power Bi table to run?
Thanks in advance
import matplotlib.pyplot as plt
#values, colors and labels
upper = [0.30, 0.60, 3.70, 5.90, 6.28]
titles = ['T1', 'T2', 'T3', 'T4', 'T5']
color_list = ['#243A5E', '#0078D4', '#50E6FF', '#8661C5', '#D59DFF']
# fn
def blockers(fig_w, fig_h, upper, color_list, titles):
lower = [0] + upper[:-1]
height = [upper[i] - lower[i] for i in range(len(upper))]
x_axis_labs = ['{}%: {}'.format(perc, val) for perc, val in zip(upper, titles)]
# init figure
plt.figure(figsize=(fig_w, fig_h))
plt.bar(x=range(len(lower)), height=height, bottom=lower, color=color_list, width=0.5)
# no borders
plt.box(False)
plt.tick_params(left=False, right=False, labelleft=False, labelbottom=False,
bottom=False)
# annotations
for i in range(len(x_axis_labs)):
plt.text(
x=range(len(x_axis_labs))[i],
y=lower[i]-0.15, # subtract a little more
s=x_axis_labs[i],
size=10,
rotation=270,
verticalalignment='center_baseline',
)
#call def
blockers(fig_w=1.5, fig_h=1.5, upper=upper, color_list=color_list, titles=titles)
Solved! Go to Solution.
Hello @jch
The sample file is given below for your quick reference.
https://drive.google.com/file/d/131uz29vhW9uQeIwshgdR1AKoo3XrFTSQ/view?usp=sharing
Regards
Kumail Raza
Did this help? Kudos are appreciated!!
Consider Accept it as the solution to help the other members find it more quickly
Hello @jch
The sample file is given below for your quick reference.
https://drive.google.com/file/d/131uz29vhW9uQeIwshgdR1AKoo3XrFTSQ/view?usp=sharing
Regards
Kumail Raza
Did this help? Kudos are appreciated!!
Consider Accept it as the solution to help the other members find it more quickly
Hello @jch
Add plt.show() in the blockers function at the end.
This will display the chart like this;
Regards
Kumail Raza
Did this help? Kudos are appreciated!!
Consider Accept it as the solution to help the other members find it more quickly!!
@Kumail I appreciate your reply. May I have request the one drive file be put on public so I may take a look.
I'm having a hard time implementing your solution.
Much appreciated
@jch Couldn't find the file upload option here therefore, shared the file through drive.
Hope this helps.
Thanks,
Kumail Raza
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
96 | |
77 | |
66 | |
53 |
User | Count |
---|---|
144 | |
105 | |
102 | |
89 | |
63 |