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)
:
float
object in python is a dot. I'm not aware of any other programming languages that would change their syntax depending on some (locale) setting but those might exist. In any case, because power bi simply executes python as it seems, there is no way it would allow to use anything else but valid python syntax. Concerning string representations on screen, the usual locale formatting is of course available and can be used within python and matplotlib. – ImportanceOfBeingErnest3,75,3,52
actually come from? Do you write them somewhere or are they generated by power bi? – ImportanceOfBeingErnest