import numpy as np import scipy.stats as ss import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from seaborn import FacetGrid df=pd.read_excel("./tmp_apply2.xlsx") sns.set_context(font_scale=10) plv_tb=pd.pivot_table(df,values="sale",index=["FactoryName","JiJXH"],columns=["Xian"],aggfunc=np.mean) plv_df["Xian"] = df["Xian"].astype(str) plv_df g = FacetGrid(plv_tb, col="Xian", col_wrap=4, sharex=False, sharey=False, height=5, aspect=1.5) sns.heatmap(g,vmin=plv_tb.min().min(), vmax=plv_tb.max().max(),cmap=sns.color_palette("RdYlGn",n_colors=10)) plt.show()如何修改代码使Xian可以展开多行,制作清晰色阶图
时间: 2023-10-31 21:04:08 浏览: 190
可以将 `col_wrap` 参数设置为 `None`,这样就可以展开多行了。同时,可以调整 `height` 和 `aspect` 参数来制作清晰的色阶图,比如将 `height` 设置为 10,`aspect` 设置为 0.8。修改后的代码如下:
```
import numpy as np
import scipy.stats as ss
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from seaborn import FacetGrid
df=pd.read_excel("./tmp_apply2.xlsx")
sns.set_context(font_scale=10)
plv_tb=pd.pivot_table(df, values="sale", index=["FactoryName","JiJXH"], columns=["Xian"], aggfunc=np.mean)
plv_tb["Xian"] = df["Xian"].astype(str)
g = FacetGrid(plv_tb, col="Xian", col_wrap=None, sharex=False, sharey=False, height=10, aspect=0.8)
sns.heatmap(g, vmin=plv_tb.min().min(), vmax=plv_tb.max().max(), cmap=sns.color_palette("RdYlGn", n_colors=10))
plt.show()
```
注意,`plv_df` 应该改为 `plv_tb`。
阅读全文