将该改代码设置为中文def correlation_plot(): correlation = data.corr() matrix_cols = correlation.columns.tolist() corr_array = np.array(correlation) trace = go.Heatmap(z = corr_array, x = matrix_cols, y = matrix_cols, colorscale='reds', colorbar = dict() , ) layout = go.Layout(dict(title = '数据集热力图', margin = dict(r = 0 ,l = 100, t = 0,b = 100, ), yaxis = dict(tickfont = dict(size = 9)), xaxis = dict(tickfont = dict(size = 9)), ) ) fig = go.Figure(data = [trace],layout = layout) py.iplot(fig)
时间: 2024-01-12 12:05:10 浏览: 138
PZ_Correlation_it_PZ_Correlation_
要将图像属性设置为中文,可以使用 Plotly 的 layout 属性来设置。具体可以在 layout 中设置 xaxis、yaxis 和 title 的属性,并使用中文字符集来避免中文乱码问题,如下所示:
```
import plotly.graph_objs as go
from plotly.offline import iplot
def correlation_plot():
correlation = data.corr()
matrix_cols = correlation.columns.tolist()
corr_array = np.array(correlation)
trace = go.Heatmap(z=corr_array,
x=matrix_cols,
y=matrix_cols,
colorscale='reds',
colorbar=dict())
layout = go.Layout(dict(title='数据集热力图',
margin=dict(r=0, l=100, t=0, b=100),
yaxis=dict(title='变量', tickfont=dict(size=9)),
xaxis=dict(title='变量', tickfont=dict(size=9)),
font=dict(family='SimHei')
)
)
fig = go.Figure(data=[trace], layout=layout)
iplot(fig)
```
其中,`font=dict(family='SimHei')` 用于设置字体为中文 SimHei 字体。其他属性的设置与英文属性设置方式相同。
阅读全文