python自定义函数画图,如何让函数在python中返回图形(使用matplotlib)?

本文探讨了如何在使用Matplotlib创建图表时避免自动显示图表的方法。作者通过定义一个自定义绘图函数myplot()来绘制数据,并希望该函数返回一个图形句柄而不是直接显示图表。文章提出了两个问题:为什么即使将myplot()的输出赋值给变量f仍能看到图表?以及如何在将myplot()的输出赋值给变量时抑制图表显示?解决方案是使用ipython notebook而非ipython notebook --pylab=inline启动。

Assume that I have some data, and I want to create a plot of this data by passing it to a custom plotting function (myplot()). I am using the matplotlib's modules in myplot().

I would like myplot() to return the handle to a figure, and not plot display the plot when I call this function. Here is a sample code and output from iPython.

2jDc6.png

I have two questions regarding this:

Why do I still see a plot, even though I am assigning the output of

myplot() to f?

What do I need to supress this plot when I am assigning the output of myplot() to a variable?

解决方案

Start ipython with

ipython notebook

rather than

ipython notebook --pylab=inline

I3VX5.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值