Python 3.x 在使用python的主成分分析中未显示图形

Python 3.x 在使用python的主成分分析中未显示图形,python-3.x,matplotlib,Python 3.x,Matplotlib,如何在主成分分析的输出中显示图形图像 import matplotlib.pyplot as plt %matplotlib inline fig = plt.figure(figsize = (8, 8)) ax = fig.add_subplot(1, 1, 1) ax.set_xlabel('Principal Component 1', fontsize = 15) ax.set_ylabel('Principal Component 2', fontsize = 15) ax.set

如何在主成分分析的输出中显示图形图像

import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure(figsize = (8, 8))
ax = fig.add_subplot(1, 1, 1)
ax.set_xlabel('Principal Component 1', fontsize = 15)
ax.set_ylabel('Principal Component 2', fontsize = 15)
ax.set_title('2 Component PCA', fontsize = 20)

targets = ['Iris - setosa', 'Iris - versicolor', 'Iris - virginica']
colors = ['r', 'g', 'b']

for target, color in zip(targets, colors):
    indicesToKeep = finalDF['target'] == target     
    ax.scatter(finalDF.loc[indicesToKeep, 'Principal Component 1'],
              finalDF.loc[indicesToKeep, 'Principal Component 2'],
              c = color, s = 50)

ax.legend(targets)
ax.grid()
ax.show()
以下是错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-21-d87d089bc5f1> in <module>
         16 ax.legend(targets)
         17 ax.grid()
--->     18 ax.show()

AttributeError: 'AxesSubplot' object has no attribute 'show'
AttributeError回溯(最近一次调用)
在里面
16轴图例(目标)
17 ax.网格()
--->18 ax.show()
AttributeError:“AxeSubPlot”对象没有属性“show”


如何在没有绘图且显示属性不工作的情况下显示图形?

这里唯一的更正是:在最后一行中,用
fig.show()替换
axis.show()


这里唯一的修正是:在最后一行中,用图show()替换轴show()


但是我的绘图没有显示..它显示的是..C:\Users\DELL\Anaconda3\lib\site packages\matplotlib\figure.py:445:UserWarning:matplotlib当前正在使用module://ipykernel.pylab.backend_inline,它是非GUI后端,因此无法显示该图。%get_backend())因为正如它所说:“您的环境是一个非GUI后端”,您可以尝试保存fig而不是
fig.show()
try
fig.savefig(“fig\u name.png”)
请记住以“.png”或“.jpg”等名称添加格式,或者您可以尝试任何其他环境。但我的绘图没有显示..它正在显示………C:\Users\DELL\Anaconda3\lib\site packages\matplotlib\figure.py:445:UserWarning:matplotlib当前正在使用module://ipykernel.pylab.backend_inline,这是一个非GUI后端,因此无法显示图形。%get_backend())因为它说:“您的环境是非GUI后端”,您可以尝试保存fig,而不是
fig.show()
try
fig.savefig(“fig_name.png”)
记住在名称中添加格式,如“.png”或“.jpg”,或者您可以尝试任何其他环境。要显示pyplot图形,使用
plt.show()
。要显示pyplot图形,请使用
plt.show()
import matplotlib.pyplot as plt
%matplotlib inline

fig = plt.figure(figsize = (8, 8))
ax = fig.add_subplot(1, 1, 1)
ax.set_xlabel('Principal Component 1', fontsize = 15)
ax.set_ylabel('Principal Component 2', fontsize = 15)
ax.set_title('2 Component PCA', fontsize = 20)

targets = ['Iris - setosa', 'Iris - versicolor', 'Iris - virginica']
colors = ['r', 'g', 'b']

for target, color in zip(targets, colors):
    indicesToKeep = finalDF['target'] == target     
    ax.scatter(finalDF.loc[indicesToKeep, 'Principal Component 1'],
              finalDF.loc[indicesToKeep, 'Principal Component 2'],
              c = color, s = 50)

ax.legend(targets)
ax.grid()
fig.show()