我正在使用python和seaborn在Power Bi中准备热图。在该软件的桌面版本上看起来还不错,但是在我发布报告时,它切掉了部分Y轴标签并更改了图表尺寸。
Power Bi桌面:
在线报告:
这是我的代码:
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()
有什么想法为什么图表与台式机版本不同?
答案 0 :(得分:0)
问题是由python 3.7版引起的。更改为3.5版即可解决此问题。