Reputation: 61134
The challenge:
How can you prevent Matplotlib from using commas in figure arguments like matplotlib.pyplot.figure(figsize=(3,75,3,5))
without changing your locale settings (and still use commas as decimal separators for the rest of your system)?
The details:
From the questions and answers in the posts What is the best data format and setup for a time series in a Python Visualization in Power BI? and What setup do you need for Python Visualizations in Power BI? Any particular matplotlib package versions or system settings?, it seems that many european Power BI users will face a few issues when it comes to Python Visualizations in Power BI. This is because regional settings and using comma as a decimal separator raises an issue in matplotlib.
In order to avoid the errors matplotlib.pyplot.figure(figsize=(3,75,3,52))
and TypeError: from_bounds() takes 4 positional arguments but 6 were given
when you're setting up a Python Visualization, it seems that you would have to:
Use non-european regional settings for you entire system, or
tell matplotlib to ignore regional settings when setting up a figure.
At least to me, It would be unthinkable to use another regional setting and decimal separator than ",". As far as I know, that would mess up the numerous other reports what we've set up in Power BI.
So I guess we're stuck with option 2.
In the post Matplotlib : Comma separated number format for axis, one of the answers shows how this can be done using:
import locale
locale.setlocale(locale.LC_ALL, "deu_deu")
import matplotlib as mpl
mpl.rcParams['axes.formatter.use_locale'] = True
But it doesn't seem to work in Power BI. I've tried with this simple dataset:
A,B
1,11
2,19
3,18
4,19
5,18
6,12
7,12
8,19
9,13
10,19
And this script:
#Locale settings
import locale
locale.setlocale(locale.LC_ALL, "deu_deu")
import matplotlib as plt
plt.rcParams['axes.formatter.use_locale'] = True
# Plot
import matplotlib.pyplot as plt
plt.plot(dataset['A'], dataset['B'])
plt.show()
But still no success:
I've also tried other arguments than "deu_deu" and I've tried setting plt.rcParams['axes.formatter.use_locale'] = True
to False
. And of course, I've tried different settings in Power BI like setting Locale for Import
under Options | Regional Settings
to English (United States)
:
Upvotes: 1
Views: 2305
Reputation: 1
Workaround by changing the decimal separator in the Control Panel worked out for me. Don't forget to close and re-open PBI after having applied it to actually apply the change.
Upvotes: 0
Reputation: 61134
Adding the line matplotlib.pyplot.figure(figsize=(3.75,3.52))
as suggested by Foxan Ng does not seem to work on my end. The only thing that does seem to work is changing the decimal separator to .
in the Windows settings under Control Panel | Region and Language | Formats | Additional Settings | Decimal Separator
(I'm still on Windows 7) . Now it works:
But now of course, I'm running the risk of messing up everything else in other Power BI reports. So I'm really hoping that the Power BI team gets on this or that others are able to provide even better answers.
Upvotes: 0
Reputation: 7151
I think this is definitely a bug that Power BI team should work on to fix it.
Similar reports by Power BI users can be found here:
https://community.powerbi.com/t5/Issues/Bug-in-python-visual/idc-p/488205
For the time being, you'll have to add the line
matplotlib.pyplot.figure(figsize=(3.75,3.52))
using .
as the decimal point to avoid Power BI generating a bugged line for you. (which also applies to any other functions that you may come across where Power BI may be generating extra codes to display the Python visuals)
Upvotes: 1