如何放大subplot matplotlib? [英] How to enlarge subplot matplotlib?

查看:50
本文介绍了如何放大subplot matplotlib?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有两个子图.注意:这是在Mac OS X 10.6.x上的matplotlib v0.99.3中.

I currently have two subplots. Note: this is in matplotlib v0.99.3 on Mac OS X 10.6.x

我有一个事件处理程序,当单击其中一个子图时,它会打印出一些内容.这只是一个临时占位符.我想发生的是单击子图时,我希望它占据整个图形(删除另一个子图并最大化以填充整个图形).我该怎么做?

I have an event-handler that when one of the subplots are clicked, it prints something. This is only a temporary place holder. What I want to happen is when the subplot is clicked, I want it to take up the whole figure (delete the other subplot and maximize to fill up the whole figure). How would I go about doing this?

推荐答案

您可以通过修改

You can do this by modifying the axes that subplot returns. That is, axes can be positioned and sized in any desired way, and subplot is just a function that returns axes positioned in a uniform grid; but once you have these axes from subplot you can arbitrarily resize and reposition them. Here's an example:

from pylab import *

axes = [None, None]

def make():
    figure()
    axes[0] = subplot(1, 2, 1)
    axes[1] = subplot(1, 2, 2)
    show()

def re_form():
    xmax = axes[1].get_position().get_points()[1][0]
    axes[1].set_axis_off()
    (x0, y0), (x1, y1) = axes[0].get_position().get_points() # xmin, ymin, xmax, ymax
    axes[0].set_position([x0, y0, xmax-x0, y1-y0])  # x, y, width, height
    show()

这里我使用了 show() 来更新绘图,但您需要使用更适合您的事件处理程序的内容.此演示适用于iPython:首先 run 该文件,然后调用 make()绘制两个轴,然后调用 re_form(),删除第二个轴并加宽第一个.

Here I used show() to update the plot, but you'll want to use something more appropriate for your event handler. This demo works with iPython: first run the file, then call make(), which draws the two axes, and then re_form(), which removes the second axis and widens the first.

这篇关于如何放大subplot matplotlib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆