简体   繁体   English

如何使Power Bi网站版本的python图表看起来像台式机版本?

[英]How to make python chart in Power Bi website version look like in desktop version?

I am preparing heatmap in Power Bi using python and seaborn. 我正在使用python和seaborn在Power Bi中准备热图。 It is looking quite fine in desktop version of this software but when I publish report it cutting of part of Y axis labels and changing size of chart. 在此软件的桌面版本中看起来还不错,但是在我发布报告时,它切掉了部分Y轴标签并更改了图表尺寸。

Power Bi Desktop: Power Bi桌面: 桌面版

Online report: 在线报告: 在线报告

Here is my code: 这是我的代码:

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np

if not dataset.empty:
    dataset['Skill Name'] = dataset['Skill Name'].str.replace(r"\(.*\)","")
    dataset['Skill Name'] = dataset['Skill Name'].str.replace(r"\-\-.*","")

    skill_name_dir = {
        "including":"inc",
        "Documentation":"Doc",
        "Design":"Dsgn",
        "Process":"Proc",
        "Architecture":"Arch",
        "Frequency":"Freq",
        "Engineering":"Engr",
        "Hardware":"Hdw",
        "Software":"Sw",
        "Power":"Pwr",
        "Termination":"Term",
        "Electromechanical":"Elmech",
        "Requirements":"Req"
    }

    for word, initial in skill_name_dir.items():
        dataset['Skill Name'] = dataset['Skill Name'].str.replace(word,initial)

    dataset['Category'] = dataset['Category'].str.replace(r"^Domain[A-Za-z\s\S]*", "Dom", regex=True)
    dataset['Category'] = dataset['Category'].str.replace(r"^Process[A-Za-z\s\S]*", "Proc", regex=True)
    dataset['Category'] = dataset['Category'].str.replace(r"^Product[A-Za-z\s\S]*", "Prod", regex=True)
    dataset['Category'] = dataset['Category'].str.replace(r"^Tools[A-Za-z\s\S]*", "Tool", regex=True)
    dataset['Category'] = dataset['Category'].str.replace(r"^Organization[A-Za-z\s\S]*", "Org", regex=True)
    dataset['Category'] = "(" + dataset['Category'] + ")"

    dataset['Manager Name'] = dataset['Manager Name'].str.replace('[^A-Z]', '', regex=True)
    dataset['Manager Name'] = "(" + dataset['Manager Name'] + ")"
    dataset['Employee Name'] = dataset['Manager Name'] + dataset['Employee Name']

    dataset = dataset.sort_values(['Category', 'Skill Name', 'Employee Name'], ascending=[True, True, False])
    dataset['Skill Name'] = dataset['Category'] + dataset['Skill Name']
    dataset['Score'] = dataset['Score'].replace(-1,np.nan)

    heatmap_data = pd.pivot_table(dataset, values='Score', index=['Skill Name'], columns='Employee Name')

    #plt.figure(figsize=(30,15))
    fig = plt.gcf()
    figsize = fig.get_size_inches()
    fig.set_size_inches(figsize*1.4)

    hm = sns.heatmap(
        heatmap_data,
        vmin=0,
        vmax=5,
        #annot=True,
        linewidths=0.01,
        square=True,
        cmap="RdYlGn"
    )

    hm.xaxis.set_ticks_position('top')

    hm.set_xticklabels(
        hm.get_xticklabels(),
        rotation=60,
        horizontalalignment='left',
        fontsize = 7,
        wrap = True
    )

    hm.set_yticklabels(
        hm.get_yticklabels(),
        fontsize = 7,
        #wrap = True
    )
    hm.set_ylabel('')    
    hm.set_xlabel('')
else:
    fig = plt.figure(figsize=(5, 1.5))
    text = fig.text(0.5, 0.5, 'No data to display.\nPlease change filters \nto display chart.', ha='center', va='center', size=20)
plt.tight_layout()
plt.show()

Any ideas why chart is different than in desktop version? 有什么想法为什么图表与台式机版本不同?

Issue was caused by version 3.7 of python. 问题是由python的3.7版本引起的。 Change to version 3.5 fixed this. 更改为版本3.5修复了此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM