[Feature Engineering] - Drawing

1 DataFrame.plt change font

from sklearn.feature_selection import mutual_info_classif
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.text import Text

dataframe = pd.read_csv("./test.csv")
dataframe.head()
array = dataframe.values
X = array[1:, 0:12]
Y = array[1:, 12]

importances = mutual_info_classif(X, Y)
feat_importances = pd.Series(importances, dataframe.columns[0:len(dataframe.columns)-1])

font = {
    
    'family': 'Times New Roman', 'weight': 'normal', 'size': 10}		# 使用Times New Roman字体。
fig = feat_importances.plot(kind='barh', color='teal', title='mutual_info_classif')
# 定义坐标名称、图例的字体字号
fig.set_ylabel("y",font)
fig.set_xlabel("x" ,font)
# 定义图标题
plt.title('mutual_info', font, x=0.5, y=1)		# 标题的位置
plt.savefig('./result.png')
plt.show()
plt.close()

2 plt.plot change font

import matplotlib.pyplot as plt
l = []
a = [[1,2,3,4,5], [11,22,33,44,55], [111,222,333,444,555]]
print(len(a))
for i in range(3):
    l.append(a[i][1])
print(l)

plt.plot(range(1, len(l) + 1), l)
plt.xlabel("The number of sensors")
plt.ylabel("Accuracy")
font = {
    
    'family':'Times New Roman','weight':'normal' ,'size':20}

plt.show()
plt.close()

3 sns.heatmap change font

import seaborn as sns
import matplotlib.pyplot as plt

# Correlation matrix
dataframe_heat = pd.read_csv("./test.csv")  # 读取数据集
cor = dataframe_heat.corr(method='pearson')

# 画图
rc = {
    
    'font.sans-serif': ['Times New Roman']}		# 用Times New Roman字体
sns.set(context='notebook', style='ticks', font_scale=0.75, rc=rc)		# 0.75调整字号
ax = sns.heatmap(cor, annot=True)
plt.savefig('./heatmap.png')
plt.show()
plt.close()

Guess you like

Origin blog.csdn.net/everyxing1007/article/details/127447344