我需要使用 python 扩展将分面条形图集成到 Power BI。我可以使用 Altair 库实现相同的效果,但无法使用 matplotlib.image 加载图像。 以下是我正在使用的数据和代码。
import altair as alt
from altair_saver import save
import pandas as pd
df = pd.DataFrame([
['Jan','2020','F1',10],['Jan','2020','F2',40],['Jan','2021','F1',85],['Jan','2021','F2',50],
['Feb','2020','F1',-50],['Feb','2020','F2',10],['Feb','2021','F1',25],['Feb','2021','F2',30],
['Mar','2020','F1',30],['Mar','2020','F2',60],['Mar','2021','F1',40],['Mar','2021','F2',80]]
,columns=['month','year','factory','val'], index=pd.RangeIndex(12, name='x'))
plot= (alt.Chart(df).mark_bar().encode(
x='year:O',
y='val:Q',
color='factory:N',
column=alt.X('month:N',sort=['Jan','Feb','Mar']),
tooltip=['year', 'month', 'factory', 'val']
).properties(
width=100, height=300
))
save(plot,"chart.png")
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread("chart.png")
imgplot = plt.imshow(img)
输出我期望的是:
它只加载了 5 分钟,然后在 python 视觉中出现错误。
是否有其他方法可以使用 seaborn 或 matplotlib 实现相同的绘图以集成到 Power BI 中?