-
Notifications
You must be signed in to change notification settings - Fork 51
/
README
190 lines (129 loc) · 4.78 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
itermplot
=========
An awesome `iTerm2 <https://www.iterm2.com/>`__ backend for Matplotlib,
so you can plot directly in your terminal.
The above is achieved with zero modifications to your Python script. For
example, the above plots are generated with the following code:
.. code:: {python}
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
plt.rcParams["font.size"] = 10
plt.figure(figsize=(8,3))
ax = plt.subplot(121)
x = np.arange(0,10,0.001)
ax.plot(x, np.sin(np.sinc(x)), 'r', lw=2)
ax.set_title('Nice wiggle')
ax = plt.subplot(122)
plt.tick_params(axis='both', left='off', top='off', right='off', bottom='off', labelleft='off', labeltop='off', labelright='off', labelbottom='off')
G = nx.random_geometric_graph(200, 0.125)
pos=nx.spring_layout(G)
nx.draw_networkx_edges(G, pos, alpha=0.2)
nx.draw_networkx_nodes(G, pos, node_color='r', node_size=12)
ax.set_title('Random graph')
plt.show()
Note: you need to run ``plt.show()`` to display the figure.
Reverse video
~~~~~~~~~~~~~
If you use a dark background in your terminal, you can enable “reverse
video” mode by adding this to your ``.profile``:
::
export ITERMPLOT=rv
TMUX support
~~~~~~~~~~~~
itermplot tries to auto-detect TMUX and behave in a sane way. Vertical
split panes do not work well due to a limitation with iTerm2. Luckily,
horizontals do though.
Animation support
~~~~~~~~~~~~~~~~~
itermplot supports animation created by matplotlib animation module.
You’ll need to install ImageMagick and have it on the path to use the
animation support. The simplest way to see if ImageMagick is installed
and valid is to run:
.. code:: {sh}
$ convert -version
Version: ImageMagick 7.0.4-4 Q16 x86_64 2017-01-14 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib
To enable animation support, you need to specifying the desired number
of frames in the output animation. For example, specify it before your
script with:
::
$ ITERMPLOT_FRAMES=30 python script.py
You can also save the resulting gif file by using ``ITERMPLOT_OUTFILE``
environment variable:
::
$ ITERMPLOT_FRAMES=30 ITERMPLOT_OUTFILE=out.gif python script.py
Currently animation does not support reverse video with ITERMPLOT=rv.
Configure lines
~~~~~~~~~~~~~~~
You can configure the number of lines used with the ``ITERMPLOT_LINES``
environment variable. For example:
.. code:: {sh}
ITERMPLOT_LINES=5 python3 simple.py
Python 2 and Python 3 support
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now supports Python 2, even if this makes me want to cry 😭
Installation
------------
Using pip
~~~~~~~~~
Install using ``pip`` using the command:
.. code:: {sh}
pip3 install itermplot
itermplot is enabled by setting ``MPLBACKEND`` in your environment. If
you use ``bash``, then this can be accomplished using the command:
.. code:: {sh}
export MPLBACKEND="module://itermplot"
Note: you can add the ``export`` line above to your ``.profile`` file so
that itermplot is always enabled in your terminal.
Testing
~~~~~~~
To test your installation you can do the following in your iTerm2
console:
::
$ echo $MPLBACKEND
module://itermplot
$ python3
Python 3.5.2 (default, Oct 24 2016, 09:14:06)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> plt.plot([1,2,3])
[<matplotlib.lines.Line2D object at 0x1041f2e48>]
>>> plt.show()
You should see a plot!
Uninstall
---------
You can disable this backend by unsetting the ``MPLBACKEND`` environment
variable.
::
$ unset MPLBACKEND
$ echo $MPLBACKEND
$ python3
Python 3.5.2 (default, Oct 24 2016, 09:14:06)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> plt.plot([1,2,3])
[<matplotlib.lines.Line2D object at 0x1106bdcc0>]
>>> plt.show()
To remove the package completely, run:
::
pip3 uninstall itermplot
Bugs
----
This backend is very alpha, so if you have a problem please raise an
Issue on GitHub and I will try to fix it.
I also accept (and appreciate!) good patches / pull request. Thanks to
`garrywu <https://github.com/garywu>`__,
`brenshanny <https://github.com/brenshanny>`__,
`hbredin <https://github.com/hbredin>`__,
`zevlg <https://github.com/zevlg>`__ for their patches so far.
Other cool things
-----------------
I encourage you to check-out some of my `other little
projects <https://github.com/daleroberts>`__. Lots more coming as I
slowly release them…