Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin 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.
Hey Guys!
I want to create a BoxPlot with a python chart. But I want to switch the x-axis between a week (Mon, Tue, ...) and month (jan, feb, ...). I think it should be possible to use a field parameter to create a slicer with the period to switch between month and day.
But how can I create my box plot? I want the period (week or month) on the X-axis and the doubleValue (from my value table) on the Y-axis. This is from my visualization pane:
I don't know how to write the code correctly, or what the next step is to create the BoxPlot.
Can somebody help me please?
Best regards,
Dominic
Solved! Go to Solution.
Hey guys!
I found out. Here is the final code:
The first part deals with the order of months/days (otherwise it would be alphabetical)
Hope this can help somebody
Hey guys!
I found out. Here is the final code:
The first part deals with the order of months/days (otherwise it would be alphabetical)
Hope this can help somebody
Hi @Anonymous ,
First, you can click here for detailed guidance on creating and using field parameters.
Then you can refer to the following example and modify the Python code according to your actual situationtry:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
# Assuming 'dataset' is your DataFrame name and it includes 'period' and 'doubleValue' columns
# 'period' column should dynamically reflect the choice between week and month, based on the field parameter selection
# Convert the 'period' column to a categorical type to ensure correct ordering
dataset['period'] = pd.Categorical(dataset['period'], categories=[...], ordered=True)
# Create the BoxPlot
sns.boxplot(x='period', y='doubleValue', data=dataset)
plt.title('BoxPlot by Period')
plt.xlabel('Period')
plt.ylabel('Double Value')
plt.xticks(rotation=45) # Rotate x-axis labels for better readability if needed
plt.show()
Best Regards,
Ada Wang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous,
thanks for your message. However, with everything I try, there is this error:
This error only occurs when I want to create a python visual, with a column diagram it works without problem.
Best regards,
Dominic