Power BI中与Python可视化相关的区域设置与Matplotlib冲突

时间:2018-08-15 12:47:12

标签: python matplotlib powerbi

挑战:

如何防止Matplotlib在matplotlib.pyplot.figure(figsize=(3,75,3,5))之类的图形参数中使用逗号而不更改语言环境设置(并且仍将逗号用作系统其余部分的小数点分隔符)?


详细信息:

从帖子What is the best data format and setup for a time series in a Python Visualization in Power BI?What setup do you need for Python Visualizations in Power BI? Any particular matplotlib package versions or system settings?的问题和答案来看,当涉及Power BI中的Python可视化时,许多欧洲Power BI用户似乎将面临一些问题。这是因为区域设置并将逗号用作小数点分隔符会在matplotlib中引起问题。

为了避免在设置Python可视化时出现错误matplotlib.pyplot.figure(figsize=(3,75,3,52))TypeError: from_bounds() takes 4 positional arguments but 6 were given,看来您必须:

  1. 为整个系统使用非欧洲区域设置,或

  2. 告诉matplotlib设置人物时忽略区域设置。

至少对我来说,使用除“,”之外的其他区域设置和小数点分隔符是不可想象的。据我所知,这会弄乱我们在Power BI中设置的其他许多报告。

所以我想我们只能选择选项2。

Matplotlib : Comma separated number format for axis帖子中,答案之一显示了如何使用以下方法完成此操作:

import locale
locale.setlocale(locale.LC_ALL, "deu_deu")
import matplotlib as mpl
mpl.rcParams['axes.formatter.use_locale'] = True

但是它似乎在Power BI中不起作用。我已经尝试过使用以下简单数据集:

A,B
1,11
2,19
3,18
4,19
5,18
6,12
7,12
8,19
9,13
10,19

这个脚本:

#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()

但仍然没有成功:

enter image description here

除了“ deu_deu”以外,我还尝试了其他参数,并且尝试将plt.rcParams['axes.formatter.use_locale'] = True设置为False。当然,我在Power BI中尝试了其他设置,例如将Locale for Import下的Options | Regional Settings设置为English (United States)

enter image description here

3 个答案:

答案 0 :(得分:1)

我认为这绝对是Power BI团队应该修复的错误。

Power BI用户的类似报告可以在这里找到:

https://community.powerbi.com/t5/Issues/Bug-in-python-visual/idc-p/488205

暂时,您必须添加该行 matplotlib.pyplot.figure(figsize=(3.75,3.52))使用.作为小数点,以避免Power BI为您生成错误的行。 (这也适用于您可能遇到的其他任何功能,其中Power BI可能会生成额外的代码来显示Python视觉效果)

答案 1 :(得分:0)

按照Foxan Ng的建议添加行matplotlib.pyplot.figure(figsize=(3.75,3.52))似乎对我没有用。 唯一可行的工作是在Windows设置.下将小数点分隔符更改为Control Panel | Region and Language | Formats | Additional Settings | Decimal Separator(我仍然在Windows 7上)。现在可以使用了:

enter image description here

但是,现在当然,我冒着将其他Power BI报表中的其他所有内容弄乱的风险。因此,我真的希望Power BI团队能够胜任这一工作,或者其他人能够提供更好的答案。

答案 2 :(得分:0)

通过更改“控制面板”中的小数点分隔符可以解决此问题。将PBI应用到实际应用更改后,别忘了关闭并重新打开PBI。