問題描述
嘗試在 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 包版本或系統設置?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!