我们经常会使用jupyter处理一些数据绘图,在pycharm中比较麻烦,在一次学校布置的作业中,要求完成图形的绘画处理,结果根据查找的绘图方法。发现利用seabron模块渲染运行之后,没有出现图形,出现了

<Axes: >

 利用jupyter绘图时,不显示图形,显示<Axes: >的解决办法_python

r

原代码:

import numpy as np
import sympy as sp
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
# 利用seaborn 进行渲染处理


# 读取数据
path = "D:\\PyCharmProjects\\pythonProject\\pythonHIgh\\resourse\\Admission_Predict_Ver1.1.csv"
path1 = "D:\\PyCharmProjects\\pythonProject\\pythonHIgh\\resourse\\Admission_Predict.csv"
data_df = pd.read_csv(path)
data_df1 = pd.read_csv(path1)

# 重置索引
data_df.index = data_df['Serial No.']
data_df1.index = data_df1['Serial No.']

# 合并数据
part_data_df = data_df[['GRE Score','TOEFL Score','University Rating','SOP','LOR','CGPA','Research','Chance of Admit']]
part_data_df1 = data_df1[['GRE Score','TOEFL Score','University Rating','SOP','LOR','CGPA','Research','Chance of Admit']]

combine_data_df = pd.concat([part_data_df,part_data_df1],axis = 0)
combine_data_df.head(5)

fig, axes = plt.subplots(figsize = (7, 6))
sns.heatmap(combine_data_df.corr(), ax=axes, annot = True, fmt='.2f',linewidths=0.03,cmap="magma")

解决办法如下:

添加以下代码:

 import seaborn as sns
from mpl_toolkits.mplot3d import Axes3D

 fig = plt.figure()
ax = fig.add_subplot(projection='3d') 
plt.show()

添加代码重新运行之后,运行结果如下:

 利用jupyter绘图时,不显示图形,显示<Axes: >的解决办法_python_02

更改后的代码如下:

import numpy as np
import sympy as sp
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
# 利用seaborn 进行渲染处理
import seaborn as sns
from mpl_toolkits.mplot3d import Axes3D

# 读取数据
path = "D:\\PyCharmProjects\\pythonProject\\pythonHIgh\\resourse\\Admission_Predict_Ver1.1.csv"
path1 = "D:\\PyCharmProjects\\pythonProject\\pythonHIgh\\resourse\\Admission_Predict.csv"
data_df = pd.read_csv(path)
data_df1 = pd.read_csv(path1)

# 重置索引
data_df.index = data_df['Serial No.']
data_df1.index = data_df1['Serial No.']

# 合并数据
part_data_df = data_df[['GRE Score','TOEFL Score','University Rating','SOP','LOR','CGPA','Research','Chance of Admit']]
part_data_df1 = data_df1[['GRE Score','TOEFL Score','University Rating','SOP','LOR','CGPA','Research','Chance of Admit']]

combine_data_df = pd.concat([part_data_df,part_data_df1],axis = 0)
combine_data_df.head(5)

fig = plt.figure()
ax = fig.add_subplot(projection='3d') 
plt.show()


fig, axes = plt.subplots(figsize = (7, 6))
sns.heatmap(combine_data_df.corr(), ax=axes, annot = True, fmt='.2f',linewidths=0.03,cmap="magma")