简体   繁体   English

Python:平行协调子图中的子图

[英]Python: Parallel coordinates subplots in subplot

I saw this example on how to create a parallel coordinate plot: Parallel Coordinates : 我看到了有关如何创建平行坐标图的示例: 平行坐标

在此处输入图片说明

This creates a nice Parallel Coordinates figure, but I would like to add this plot to an already existing figure in a subplot (there should be another plot next to it in the same plot). 这将创建一个不错的“平行坐标”图形,但我想将此图形添加到子图形中已经存在的图形中(同一图形中应在其旁边有另一个图形)。

For the already existing figure, the figure and axes are defined as: 对于已经存在的图形,图形和轴定义为:

fig = plt.figure(figsize=plt.figaspect(2.))
ax =  fig.add_subplot(1,2,1)

For the Parallel Coordinates, they suggest: 对于平行坐标,他们建议:

fig, axes = plt.subplots(1, dims-1, sharey=False)

How can I reconcile both initializations of the figure and the ax(es)? 如何协调图形和斧头的初始化?

One option is to create all the axes using subplots then just shift the location of the one that you don't want to have wspace=0 as is done for the Parallel Coordinate plots: 一种选择是使用subplots创建所有轴,然后像平移坐标subplots一样移动不希望wspace=0的轴的位置:

import matplotlib.pylab as plt

dims = 4
fig, axes = plt.subplots(1, dims-1 + 1, sharey=False)

plt.subplots_adjust(wspace=0)

ax1 = axes[0]
pos = ax1.get_position()
ax1.set_position(pos.translated(tx = -0.1,ty=0))

在此处输入图片说明

I have added 1 to the number of columns creates (leaving it explicitly -1+1) and set wspace=0 which draws all the plots adjacent to one another with no space inbetween. 我在创建的列数上加了1(将其显式保留为-1 + 1),并设置了wspace=0 ,它绘制了所有相邻的图,并且它们之间没有空格。 Take the left most axes and get the position which is a Bbox . 取最左边的轴并获得Bbox的位置。 This is nice as it gives you the ability to translate it by tx=-0.1 separating your existing figure. 很好,因为它使您能够通过tx=-0.1分隔现有图形来进行翻译。

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

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