Coder Social home page Coder Social logo

itermplot's Introduction

itermplot

An awesome iTerm2 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:

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.

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:

pip3 install itermplot

itermplot is enabled by setting MPLBACKEND in your environment. If you use bash, then this can be accomplished using the command:

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 is backend is very alpha, so if you have a problem please raise an Issue on GitHub and I will try to fix it. Thanks.

I also accept (and appreciate!) patches / pull request.

Other cool things

I encourage you to check-out some of my other little projects. Lots more coming as I slowly release them...

itermplot's People

Contributors

daleroberts avatar brenshanny avatar hbredin avatar

Watchers

iapilgrim avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.