简体   繁体   English

plt.subplot 中的 n += 1 是什么意思

[英]what does n += 1 in plt.subplot mean

I don't understand how the n +=1 variable below made the distplot visualization into 3 columns我不明白下面的 n +=1 变量如何将 distplot 可视化分为 3 列

n=0
for x in ['Age', 'Annual Income (k$)', 'Spending Score (1-100)']:
    n +=1
    plt.subplot(1,3,n)
    plt.subplots_adjust(hspace=0.5,wspace = 0.5)
    sns.distplot(df[x], bins = 20)
    plt.title('Displot of {}'.format(x))
plt.show()

pls see attached photo of distplot enter image description here请参阅 distplot 的附加照片在此处输入图像描述

The third parameter of plt.subplot represents the index. plt.subplot 的第三个参数代表索引。 This may be helpful to you: https://matplotlib.org/3.3.0/api/_as_gen/matplotlib.pyplot.subplot.html这可能对您有帮助: https://matplotlib.org/3.3.0/api/_as_gen/matplotlib.pyplot.subplot.html

"The position of the subplot described by one of “其中一个描述的子图的 position

Three integers (nrows, ncols, index).三个整数(nrows、ncols、index)。 The subplot will take the index position on a grid with nrows rows and ncols columns.子图将在具有 nrows 行和 ncols 列的网格上获取索引 position。 index starts at 1 in the upper left corner and increases to the right.索引从左上角的 1 开始,向右增加。 index can also be a two-tuple specifying the (first, last) indices (1-based, and including last) of the subplot, eg, fig.add_subplot(3, 1, (1, 2)) makes a subplot that spans the upper 2/3 of the figure. index 也可以是一个二元组,指定子图的(第一个,最后一个)索引(从 1 开始,包括最后一个),例如, fig.add_subplot(3, 1, (1, 2)) 生成一个跨越的子图图的上 2/3。

A 3-digit integer.一个 3 位 integer。 The digits are interpreted as if given separately as three single-digit integers, ie fig.add_subplot(235) is the same as fig.add_subplot(2, 3, 5).这些数字被解释为好像分别作为三个单位数整数给出,即 fig.add_subplot(235) 与 fig.add_subplot(2, 3, 5) 相同。 Note that this can only be used if there are no more than 9 subplots."请注意,这只能在不超过 9 个子图的情况下使用。”

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

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