尝试在 Power BI 中插入 Python 可视化时,我不断收到错误 TypeError: from_bounds() 需要 4 个位置参数,但给出了 6 个
.虽然看起来 Matplotlib 是这里的问题,但我不知道这是否是根本原因.
我的系统:
Windows 7, 64 位Power BI 2018 年 8 月Python 3.6.6.0Matplotlib 2.2.2熊猫 0.23.4
我不能 100% 确定这实际上是一个版本问题,但我想不出其他任何事情,因为我使用的是在帖子中成功使用的相同数据集
编辑 1 - 完整的错误消息:
<块引用>反馈类型:皱眉(错误)
时间戳:2018-08-15T09:58:44.0322850Z
当地时间:2018-08-15T11:58:44.0322850+02:00
会话 ID:85df81af-81bb-4f82-a7f4-062b315cb370
发布:2018 年 8 月
产品版本:2.61.5192.601 (18.08) (x64)
错误消息:Python 脚本错误.回溯(最近一次通话最后):文件PythonScriptWrapper.PY",第 6 行,在matplotlib.pyplot.figure(figsize=(3,75,3,52777777777778)) 文件C:UsersuserinfoAppDataLocalContinuumAnaconda3libsite-packagesmatplotlibpyplot.py",第 548 行,如图**kwargs) 文件 "C:UsersuserinfoAppDataLocalContinuumAnaconda3libsite-packagesmatplotlibackend_bases.py",第 160 行,在 new_figure_manager 中fig = fig_cls(*args, **kwargs) 文件 "C:UsersuserinfoAppDataLocalContinuumAnaconda3libsite-packagesmatplotlibfigure.py",第 361 行,在 init 中self.bbox_inches = Bbox.from_bounds(0, 0, *figsize) TypeError: from_bounds() 接受 4 个位置参数,但给出了 6 个
操作系统版本:Microsoft Windows NT 6.1.7601 Service Pack 1 (x64 nb-NO)
CLR 版本:4.7 或更高版本 [Release Number = 461310]
峰值虚拟内存:4.16 GB
私人内存:398 MB
峰值工作集:532 MB
IE 版本:11.0.9600.19035
用户 ID:ID 号
工作簿包信息:1* - nb-NO,查询组:0,fastCombine:启用,运行BackgroundAnalysis:True.
已启用遥测:是的
模型默认模式:导入
快照跟踪日志:C:UsersuserinfoAppDataLocalMicrosoftPowerBI桌面FrownSnapShot1416353677.zip
性能跟踪日志:C:UsersuserinfoAppDataLocalMicrosoftPower BI桌面PerformanceTraces.zip
启用预览功能:PBI_PythonSupportEnabled
禁用预览功能:PBI_shapeMapVisualEnabled PBI_newFromWebPBI_SpanishLinguisticsEnabled CustomConnectors PBI_variationUIChangePBI_canvasTooltips PBI_showIncrementalRefreshPolicyPBI_compositeModels PBI_DB2DQ
禁用 DirectQuery 选项:PBI_DirectQuery_UnrestrictedTreatHanaAsRelationalSource
云:全球云
DPI 比例:100%
支持的服务:Power BI
公式:
第 1 节;
共享时间序列 = 让Source = Csv.Document(File.Contents("C:data imeseries.csv"),[Delimiter=",",列=2,编码=1252,QuoteStyle=QuoteStyle.None]),#"PromoteHeaders" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Value", Int64.Type}}) in#"改变类型";
好的,现在很明显错误来自哪里.
在行中(Power BI 即时生成):
matplotlib.pyplot.figure(figsize=(5,87473572938689,6,87403100775194))
它获取您的语言环境中的尺寸(在这种情况下使用,"作为小数点)并将其传递给 figsize
.
而 figsize 接受 (width, height) 的元组以英寸为单位作为输入,5,87473572938689,6,87403100775194
被视为 4 个参数,而不是 2 个,这会导致错误.
所以要解决这个问题,您可以将 figsize
(使用带有 .
作为小数点的值)显式传递给 plt.figure
,即:
import matplotlib.pyplot as pltplt.figure(figsize=(5.874,6.874))plt.plot(数据集['日期'],数据集['值'])plt.show()
或者将 Power BI 中的区域设置更改为使用 .
作为小数点而不是 ,
.
I keep getting the error TypeError: from_bounds() takes 4 positional arguments but 6 were given
when trying to insert a Python Visualization in Power BI.
Though it seems that Matplotlib is the problem here, I don't know if that is the root cause.
My system:
Windows 7, 64 bit
Power BI august 2018
Python 3.6.6.0
Matplotlib 2.2.2
Pandas 0.23.4
I can't be 100% sure that this is in fact a version problem, but I can't think of anything else because I'm using the same dataset that was successfully used in the post What is the best data format for a time series in a Python Visualization in Power BI?.
Data:
Date,Value
2017-01-12,1
2017-01-13,4
2017-01-14,2
2017-01-15,4
2017-01-16,2
2017-01-17,2
2017-01-18,2
2017-01-19,5
2017-01-20,5
2017-01-21,5
2017-01-22,5
2017-01-23,6
2017-01-24,3
2017-01-25,6
2017-01-26,6
2017-01-27,5
2017-01-28,8
2017-01-29,4
2017-01-30,2
Code:
import matplotlib.pyplot as plt
plt.plot(dataset['Date'], dataset['Value'])
plt.show()
Error message screenshot:
Edit 1 - The complete error message:
Feedback Type: Frown (Error)
Timestamp: 2018-08-15T09:58:44.0322850Z
Local Time: 2018-08-15T11:58:44.0322850+02:00
Session ID: 85df81af-81bb-4f82-a7f4-062b315cb370
Release: August, 2018
Product Version: 2.61.5192.601 (18.08) (x64)
Error Message: Python script error. Traceback (most recent call last): File "PythonScriptWrapper.PY", line 6, in matplotlib.pyplot.figure(figsize=(3,75,3,52777777777778)) File "C:UsersuserinfoAppDataLocalContinuumAnaconda3libsite-packagesmatplotlibpyplot.py", line 548, in figure **kwargs) File "C:UsersuserinfoAppDataLocalContinuumAnaconda3libsite-packagesmatplotlibackend_bases.py", line 160, in new_figure_manager fig = fig_cls(*args, **kwargs) File "C:UsersuserinfoAppDataLocalContinuumAnaconda3libsite-packagesmatplotlibfigure.py", line 361, in init self.bbox_inches = Bbox.from_bounds(0, 0, *figsize) TypeError: from_bounds() takes 4 positional arguments but 6 were given
OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1 (x64 nb-NO)
CLR Version: 4.7 or later [Release Number = 461310]
Peak Virtual Memory: 4.16 GB
Private Memory: 398 MB
Peak Working Set: 532 MB
IE Version: 11.0.9600.19035
User ID: IDnumber
Workbook Package Info: 1* - nb-NO, Query Groups: 0, fastCombine: Enabled, runBackgroundAnalysis: True.
Telemetry Enabled: True
Model Default Mode: Import
Snapshot Trace Logs: C:UsersuserinfoAppDataLocalMicrosoftPower BI DesktopFrownSnapShot1416353677.zip
Performance Trace Logs: C:UsersuserinfoAppDataLocalMicrosoftPower BI DesktopPerformanceTraces.zip
Enabled Preview Features: PBI_PythonSupportEnabled
Disabled Preview Features: PBI_shapeMapVisualEnabled PBI_newFromWeb PBI_SpanishLinguisticsEnabled CustomConnectors PBI_variationUIChange PBI_canvasTooltips PBI_showIncrementalRefreshPolicy PBI_compositeModels PBI_DB2DQ
Disabled DirectQuery Options: PBI_DirectQuery_Unrestricted TreatHanaAsRelationalSource
Cloud: GlobalCloud
DPI Scale: 100%
Supported Services: Power BI
Formulas:
section Section1;
shared timeseries = let Source = Csv.Document(File.Contents("C:data imeseries.csv"),[Delimiter=",", Columns=2, Encoding=1252, QuoteStyle=QuoteStyle.None]), #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Value", Int64.Type}}) in #"Changed Type";
OK now it's obvious where the error comes from.
In the line (which Power BI generates on the fly):
matplotlib.pyplot.figure(figsize=(5,87473572938689,6,87403100775194))
It grabs the dimensions in your locale (which in this case use ',' as decimal point) and passes it to figsize
.
While figsize accepts a tuple of (width, height) in inches as input, 5,87473572938689,6,87403100775194
is treated as 4 arguments, instead of 2, which causes the error.
So to work around this, you can either explicitly pass figsize
(using values with .
as decimal point) to plt.figure
, i.e.:
import matplotlib.pyplot as plt
plt.figure(figsize=(5.874,6.874))
plt.plot(dataset['Date'], dataset['Value'])
plt.show()
Or change the locale in Power BI to one which use .
as decimal points instead of ,
.
这篇关于Power BI 中的 Python 可视化需要什么设置?任何特定的 matplotlib 包版本或系统设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!