我可以阻止Spyder临时显示嵌入式图像吗?

时间:2018-08-31 12:52:02

标签: python matplotlib ipython spyder

在Spyder IDE中,我想保留嵌入式控制台绘图(我不想为每个绘图生成单独的窗口),但是我想以编程方式禁用绘图,即在不同的单元格中。

在我的工作流程中,我需要绘制一些简单的图形,然后生成图形并将其保存为视频帧(成千上万个)。我的框架是通过加载jpg图像,然后叠加一些注释即创建的;

Ltac destruct_exs_conjs :=
  repeat match goal with
  | H : exists _, _ |- _ => destruct H
  | H : _ /\ _ |- _ => destruct H
  end; subst.

Lemma le_dec_aux (t1 t2 : t) (n : nat) :
  height t1 + height t2 <= n ->
  {le t1 t2} + {~le t1 t2}.
Proof.
  revert t1 t2.
  induction n as [| n IH]; intros t1 t2 H.
  - destruct t1; simpl in H; omega.
  - destruct t1, t2.
    + eauto using le.
    + clear. right. intro contra. dependent induction contra.
      apply le_canonical_form_A_left in contra1; subst. eauto.
    + clear. right. intro contra. dependent induction contra.
      apply le_canonical_form_A_left in contra1; subst. eauto.
    + clear. right. intro contra. dependent induction contra.
      apply le_canonical_form_B_left in contra1; destruct_exs_conjs. eauto.
    + simpl in H.
      destruct (IH t1 t2); try omega.
      * eauto using le.
      * right. intro contra. apply le_inversion_B in contra. contradiction.
    + clear. right. intro contra. dependent induction contra.
      apply le_canonical_form_B_left in contra1; destruct_exs_conjs. eauto.
    + clear. right. intro contra. dependent induction contra.
      apply le_canonical_form_C_left in contra1; destruct_exs_conjs. eauto.
    + clear. right. intro contra. dependent induction contra.
      apply le_canonical_form_C_left in contra1; destruct_exs_conjs. eauto.
    + simpl in H.
      destruct (IH t2 t1); try omega.
      * eauto using le.
      * right. intro contra. apply le_inversion_C in contra. contradiction.
Qed.

Lemma le_dec' (t1 t2 : t) :
  { le t1 t2 } + { ~le t1 t2 }.
Proof.
  destruct (le_dec_aux t1 t2 (height t1 + height t2)); auto.
Qed.

我想保留内联后端; for jpg_path in path_list: img = mpl.image.imread(jpg_path) ax.imshow(img) ax.text(etc...) fig.savefig(etc...)

但是请关闭类似%matplotlib inline之类的绘图功能。

但是plt.ioff()仅适用于plt.ioff()后端,而不适用于%matplotlib qt

在很多情况下,我忘记更改为inline(因为它不是python命令,因此我必须将其分别输入到控制台中),然后再%matplotlib qt-得到10000张图像被发布在控制台中,冻结了我的机器。

1 个答案:

答案 0 :(得分:1)

好的,我想我找到了答案,这要归功于这个答案;

https://stackoverflow.com/a/46360516/789215

关键是用于线魔术get_ipython().run_line_magic('matplotlib', 'inline')的python命令。我创建了一个上下文管理器来包装我的视频帧。

from IPython import get_ipython

class NoPlots:
    def __enter__(self):
        get_ipython().run_line_magic('matplotlib', 'qt')
        plt.ioff()
    def __exit__(self, type, value, traceback):
        get_ipython().run_line_magic('matplotlib', 'inline')
        plt.ion()

还是有更好的方法?