Convert Figma logo to code with AI

daleroberts logoitermplot

An awesome iTerm2 backend for Matplotlib, so you can plot directly in your terminal.

1,491
51
1,491
25

Top Related Projects

matplotlib: plotting with Python

15,979

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!

12,383

Statistical data visualization in Python

19,206

Interactive Data Visualization in the browser, from Python

With Holoviews, your data visualizes itself.

9,213

Declarative statistical visualization library for Python

Quick Overview

itermplot is a Python library that enables inline plotting in iTerm2, allowing users to display matplotlib plots directly in the terminal. This tool enhances the workflow for data scientists and developers who work extensively with command-line interfaces, providing a seamless integration of data visualization within the terminal environment.

Pros

  • Enables inline plotting in iTerm2, improving workflow efficiency
  • Supports various matplotlib plot types and customizations
  • Easy to integrate with existing Python scripts and Jupyter notebooks
  • Provides a convenient way to visualize data without leaving the terminal

Cons

  • Limited to iTerm2 on macOS, not available for other terminal emulators or operating systems
  • May require additional setup and configuration for some users
  • Potential performance issues with large or complex plots
  • Limited documentation and community support compared to more mainstream plotting libraries

Code Examples

  1. Basic line plot:
import numpy as np
import matplotlib.pyplot as plt
from itermplot import show

x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
show()
  1. Scatter plot with custom colors:
import numpy as np
import matplotlib.pyplot as plt
from itermplot import show

x = np.random.rand(50)
y = np.random.rand(50)
colors = np.random.rand(50)
plt.scatter(x, y, c=colors, alpha=0.5)
show()
  1. Bar plot with error bars:
import numpy as np
import matplotlib.pyplot as plt
from itermplot import show

categories = ['A', 'B', 'C', 'D']
values = [3, 7, 2, 5]
errors = [0.5, 1, 0.3, 0.8]

plt.bar(categories, values, yerr=errors, capsize=5)
plt.ylabel('Values')
show()

Getting Started

To use itermplot, follow these steps:

  1. Install the library using pip:

    pip install itermplot
    
  2. In your Python script, import the show function from itermplot:

    from itermplot import show
    
  3. Create your matplotlib plot as usual, then call show() instead of plt.show():

    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.linspace(0, 10, 100)
    y = np.sin(x)
    plt.plot(x, y)
    show()
    
  4. Run your script in iTerm2 to see the inline plot.

Competitor Comparisons

matplotlib: plotting with Python

Pros of matplotlib

  • Comprehensive plotting library with extensive functionality
  • Large community and extensive documentation
  • Supports a wide range of output formats

Cons of matplotlib

  • Can be complex for simple plotting tasks
  • Requires more code for basic plots
  • May have slower performance for real-time plotting

Code Comparison

matplotlib:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)
plt.plot(x, y)
plt.show()

itermplot:

import numpy as np
from itermplot import plot

x = np.linspace(0, 10, 100)
y = np.sin(x)
plot(x, y)

Summary

matplotlib is a powerful and versatile plotting library with a large ecosystem, while itermplot focuses on simplifying plotting within iTerm2. matplotlib offers more features and customization options but may require more code for basic plots. itermplot provides a more streamlined approach for quick visualizations in the terminal but is limited to iTerm2 users.

15,979

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!

Pros of plotly.py

  • Interactive and web-based visualizations
  • Wide range of chart types and customization options
  • Supports both static and dynamic data updates

Cons of plotly.py

  • Steeper learning curve for beginners
  • Requires more setup and dependencies
  • Larger file sizes for complex visualizations

Code Comparison

plotly.py:

import plotly.graph_objects as go

fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.show()

itermplot:

import matplotlib.pyplot as plt

plt.bar([1, 2, 3], [2, 3, 1])
plt.show()

Summary

plotly.py offers more advanced features and interactivity, making it suitable for complex data visualization projects. However, it comes with a steeper learning curve and more setup requirements. itermplot, on the other hand, provides a simpler approach for basic plotting within the terminal, making it more accessible for quick visualizations during development. The choice between the two depends on the specific needs of the project and the desired level of interactivity and customization.

12,383

Statistical data visualization in Python

Pros of seaborn

  • More comprehensive statistical visualization library with a wide range of plot types
  • Built on top of matplotlib, offering enhanced aesthetics and additional features
  • Extensive documentation and large community support

Cons of seaborn

  • Steeper learning curve due to its extensive functionality
  • Can be slower for simple plots compared to basic matplotlib or itermplot

Code comparison

seaborn:

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme()
tips = sns.load_dataset("tips")
sns.scatterplot(data=tips, x="total_bill", y="tip")
plt.show()

itermplot:

import matplotlib.pyplot as plt
from itermplot import show

plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
show()

Key differences

  • seaborn focuses on statistical visualizations and offers a wide range of plot types, while itermplot is primarily designed for inline plotting in iTerm2
  • itermplot provides a simpler interface for basic plots, while seaborn offers more customization options and statistical features
  • seaborn integrates well with pandas DataFrames, making it easier to work with structured data
19,206

Interactive Data Visualization in the browser, from Python

Pros of Bokeh

  • More comprehensive and feature-rich plotting library
  • Supports interactive visualizations for web browsers
  • Large community and extensive documentation

Cons of Bokeh

  • Steeper learning curve due to its complexity
  • Heavier resource usage, especially for large datasets
  • Requires more setup for simple plots

Code Comparison

itermplot:

import matplotlib.pyplot as plt
import itermplot

plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()

Bokeh:

from bokeh.plotting import figure, show

p = figure(title="Simple line example", x_axis_label='x', y_axis_label='y')
p.line([1, 2, 3, 4], [1, 4, 9, 16], line_width=2)
show(p)

Key Differences

  • itermplot focuses on displaying matplotlib plots in iTerm2, while Bokeh is a standalone plotting library
  • Bokeh generates interactive HTML outputs, whereas itermplot produces static images in the terminal
  • itermplot is simpler to use for basic plots, while Bokeh offers more customization options

Use Cases

  • itermplot: Quick data exploration in iTerm2 terminal
  • Bokeh: Creating interactive web-based visualizations and dashboards

With Holoviews, your data visualizes itself.

Pros of HoloViews

  • More comprehensive data visualization library with a wide range of plot types and customization options
  • Seamless integration with other HoloViz tools like Panel and Bokeh for interactive visualizations
  • Supports both static and dynamic/streaming data sources

Cons of HoloViews

  • Steeper learning curve due to its extensive functionality and API
  • Requires more setup and dependencies compared to the lightweight itermplot
  • May be overkill for simple plotting tasks or quick data exploration

Code Comparison

itermplot:

import matplotlib.pyplot as plt
import itermplot

plt.plot([1, 2, 3, 4])
plt.show()

HoloViews:

import holoviews as hv
import numpy as np

hv.extension('bokeh')
curve = hv.Curve(np.array([1, 2, 3, 4]))
hv.render(curve)

Both libraries aim to enhance data visualization, but HoloViews offers a more comprehensive solution with greater flexibility and interactivity, while itermplot focuses on displaying matplotlib plots directly in iTerm2 terminals.

9,213

Declarative statistical visualization library for Python

Pros of Altair

  • More versatile and powerful for creating a wide range of statistical visualizations
  • Declarative approach allows for easier creation of complex, interactive charts
  • Better integration with web-based environments and Jupyter notebooks

Cons of Altair

  • Steeper learning curve due to its more comprehensive feature set
  • Requires more setup and dependencies compared to the simplicity of itermplot
  • May be overkill for quick, simple plots in terminal environments

Code Comparison

itermplot:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x))
plt.show()

Altair:

import altair as alt
import pandas as pd

data = pd.DataFrame({'x': range(100), 'y': np.sin(np.linspace(0, 10, 100))})
alt.Chart(data).mark_line().encode(x='x', y='y')

Summary

While itermplot excels in simplicity and terminal-based plotting, Altair offers a more powerful and flexible approach to data visualization. itermplot is ideal for quick, simple plots directly in the terminal, whereas Altair shines in creating complex, interactive visualizations for web and notebook environments. The choice between the two depends on the specific use case and the level of visualization complexity required.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

itermplot

pip install itermplot==0.5

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.

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:

$ 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:

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:

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 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, brenshanny, hbredin, zevlg for their patches so far.

Other cool things

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