简体   繁体   English

如何让我的matplotlib图超出轴?

[英]How do I let my matplotlib plot go beyond the axes?

I have to translate an image plotting script from matlab to matplotlib/pylab, and I'm trying to achieve the same effect as the matlab image below: 我必须将图像绘制脚本从matlab转换为matplotlib / pylab,我试图获得与下面的matlab图像相同的效果:

使用matlab生成的图像

As you can see, the z order of the plots seem to be higher than the z order of the grid, so the markers are not hidden by the axes. 如您所见,图的z顺序似乎高于网格的z顺序,因此标记不会被轴隐藏。 However, I can't figure out a way to do the same with my matplotlib image: 但是,我无法找到一种方法来对我的matplotlib图像做同样的事情:

使用matplotlib生成的eimage

I'm wondering if it is possible to get the same display without having to increase the limits of the y axis. 我想知道是否可以在不增加y轴限制的情况下获得相同的显示。

To get the marker to show beyond the axes you can turn the clipping off. 要使标记显示在轴之外,您可以关闭剪辑。 This can be done using the keyword argument in the plot command clip_on=False . 这可以使用plot命令clip_on=False的keyword参数来完成。

For example: 例如:

import matplotlib.pyplot as plt
plt.plot(range(5), range(5), 'ro', markersize=20, clip_on=False, zorder=100)
plt.show()

在此输入图像描述

This is a complete example of how to use the zorder kwarg: http://matplotlib.sourceforge.net/examples/pylab_examples/zorder_demo.html 这是如何使用zorder kwarg的完整示例: http ://matplotlib.sourceforge.net/examples/pylab_examples/zorder_demo.html
Note that a higher z-order equates to a graph-element being more in the foreground. 请注意,较高的z顺序等同于前景中更多的图元素。

For your second question, have a look at the figsize kwarg to instances of the Figure class: http://matplotlib.sourceforge.net/api/figure_api.html?highlight=figsize#matplotlib.figure.Figure 对于你的第二个问题,请看一下figsize kwarg到Figure类的实例: httpfigsize highlight figsize figize figsize matplotlib.figure.Figure

If you run into issues, please post some of your code and we'll be able to give more-detailed recommendations. 如果您遇到问题,请发布一些代码,我们将能够提供更详细的建议。 Best of luck. 祝你好运。

如果您一个接一个地绘制线条,只需更改绘图调用的顺序即可修复z顺序。

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

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