简体   繁体   English

如何删除另一个数字matplotlib?

[英]How to remove the other figure matplotlib?

i am new to this, can anybody tell how to remove the other figure?My code is as follows:我是新手,有人能告诉我如何删除另一个数字吗?我的代码如下:

fig, axes = plt.subplots(1, 2, sharey=True)
fig.set_size_inches(20, 10)

# use the same set of colors as above to compare side to side of the two graphs
colors = ['blue', 'green', 'red', 'purple', 'orange']
for e in set(kmeans.labels_):
    mark = kmeans.labels_ == e
    axes[0].scatter(feature_pca[:, 0][mark], feature_pca[:, 1][mark], color=colors[e], label=e, alpha=0.9)
axes[0].legend()

PS- if i am making any change to fig, axes = plt.subplots(1, 2, sharey=True), i am getting error: TypeError: 'AxesSubplot' object is not subscriptable PS-如果我对图进行任何更改,axes = plt.subplots(1, 2, sharey=True),我会收到错误消息:TypeError: 'AxesSubplot' object is not subscriptable

在此处输入图像描述

With

fig, axes = plt.subplots(1, 2, sharey=True)

you create a window with a grid of 1x2 subplots (so two in total).您创建了一个 window,其中包含 1x2 子图的网格(总共两个)。 This means you get an array of with 2 axes.这意味着你得到一个 2 轴的数组。

Now to remove the second subplot you'd have to use现在要删除您必须使用的第二个子图

    fig, axes = plt.subplots(1, 1, sharey=True)

In this case you get only one axes object, not an array.在这种情况下,您只会得到一个轴 object,而不是数组。 So to make that work you will have to replace axes[0] with just axes .因此,要完成这项工作,您必须将axes[0]替换为axes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM