Format: application/x-python-code
1 o
2
3 ��h� � @ sp d Z ddlmZ ddlmZ ddlmZmZmZ ddl m
4 Z
5 ddlmZ ej
6 ddd d
7 �ZeG dd� de��Zd
8 S )z@Implementation of magic functions for matplotlib/pylab support.
9 � )�Application)�magic_arguments)�Magics�magics_class�
10 line_magic)�skip_doctest)�warn�gui�?z�Name of the matplotlib backend to use such as 'qt' or 'widget'.
11 If given, the corresponding matplotlib backend is used,
12 otherwise it will be matplotlib's default
13 (which you can set in your matplotlib config file).
14 )�nargs�helpc @ sx e Zd ZdZeee�� ejddddd�eddd ������Z eee�� ejd
15 dddd
16 �eddd������Z
17 dd� ZdS )�PylabMagicsz,Magics related to matplotlib's pylab supportz-lz--list�
18 store_truez"Show available matplotlib backends)�actionr � c C sV t �| j|�}|jrddlm} td|� � dS | j�|j �\}}| �
19 |j |� dS )a Set up matplotlib to work interactively.
20
21 This function lets you activate matplotlib interactive support
22 at any point during an IPython session. It does not import anything
23 into the interactive namespace.
24
25 If you are using the inline matplotlib backend in the IPython Notebook
26 you can set which figure formats are enabled using the following::
27
28 In [1]: from matplotlib_inline.backend_inline import set_matplotlib_formats
29
30 In [2]: set_matplotlib_formats('pdf', 'svg')
31
32 The default for inline figures sets `bbox_inches` to 'tight'. This can
33 cause discrepancies between the displayed image and the identical
34 image created using `savefig`. This behavior can be disabled using the
35 `%config` magic::
36
37 In [3]: %config InlineBackend.print_figure_kwargs = {'bbox_inches':None}
38
39 In addition, see the docstrings of
40 `matplotlib_inline.backend_inline.set_matplotlib_formats` and
41 `matplotlib_inline.backend_inline.set_matplotlib_close` for more information on
42 changing additional behaviors of the inline backend.
43
44 Examples
45 --------
46 To enable the inline backend for usage with the IPython Notebook::
47
48 In [1]: %matplotlib inline
49
50 In this case, where the matplotlib default is TkAgg::
51
52 In [2]: %matplotlib
53 Using matplotlib backend: TkAgg
54
55 But you can explicitly request a different GUI backend::
56
57 In [3]: %matplotlib qt
58
59 You can list the available backends using the -l/--list option::
60
61 In [4]: %matplotlib --list
62 Available matplotlib backends: ['osx', 'qt4', 'qt5', 'gtk3', 'gtk4', 'notebook', 'wx', 'qt', 'nbagg',
63 'gtk', 'tk', 'inline']
64 r )�'_list_matplotlib_backends_and_gui_loopsz!Available matplotlib backends: %sN)r �parse_argstring�
65 matplotlib�listZIPython.core.pylabtoolsr �print�shellZenable_matplotlibr �_show_matplotlib_backend)�self�line�argsr r �backend� r �Oc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/magics/pylab.pyr ) s 5��zPylabMagics.matplotlibz--no-import-allNz�Prevent IPython from performing ``import *`` into the interactive namespace.
66
67 You can govern the default behavior of this flag with the
68 InteractiveShellApp.pylab_import_all configurable.
69 )r �defaultr c C s� t �| j|�}|jdu r(t�� r%t�� }z|j}W n ty$ d}Y nw d}n|j }| j j
70 |j|d�\}}}| �|j|� t
71 d� t
72 d� |rStd| d � dS dS )a Load numpy and matplotlib to work interactively.
73
74 This function lets you activate pylab (matplotlib, numpy and
75 interactive support) at any point during an IPython session.
76
77 %pylab makes the following imports::
78
79 import numpy
80 import matplotlib
81 from matplotlib import pylab, mlab, pyplot
82 np = numpy
83 plt = pyplot
84
85 from IPython.display import display
86 from IPython.core.pylabtools import figsize, getfigs
87
88 from pylab import *
89 from numpy import *
90
91 If you pass `--no-import-all`, the last two `*` imports will be excluded.
92
93 See the %matplotlib magic for more details about activating matplotlib
94 without affecting the interactive namespace.
95 NT)�
96 import_allzO%pylab is deprecated, use %matplotlib inline and import the required libraries.z>Populating the interactive namespace from numpy and matplotlibz.pylab import has clobbered these variables: %sz8
97 `%matplotlib` prevents importing * from pylab and numpy)r r �pylabZ
98 no_import_allr Zinitialized�instanceZpylab_import_all�AttributeErrorr Zenable_pylabr r r r )r r r Zappr r r Z clobberedr r r r j s, %
99
100 ��
101 ��zPylabMagics.pylabc C s |r|dkrt d| � dS dS )z'show matplotlib message backend message�autozUsing matplotlib backend: %sN)r )r r r r r r r � s �z$PylabMagics._show_matplotlib_backend)r )�__name__�
102 __module__�__qualname__�__doc__r r r �argument�
103 magic_gui_argr r r r r r r r
104 % s(
105 �;�4r
106 N)r'