daleroberts / itermplot

An awesome iTerm2 backend for Matplotlib, so you can plot directly in your terminal.
1.49k stars 51 forks source link

Issue with subplots in tmux #46

Closed brijow closed 3 years ago

brijow commented 3 years ago

In the README, the sample test subplots work fine in my usual terminal, but do not work in a tmux window.

However, when I plot a single subplot at a time, they do work.

This script is what I am referring to (from the README). Running the whole thing shows nothing. Calling plt.show() before drawing on the second subplot will correctly display first subplot. If I then draw second subplot and call plt.show() again, now the second shows but first disappears. When running the full script, neither show up, (in TMUX only seeing this issue).

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()
brijow commented 3 years ago

Just to follow up here with a similar issue since I believe it is related:

In tmux if you change panes or resize or scroll, the plots disappear. However recalling plt.show() brings them back in that case (assuming they successfully were drawn the first time).

daleroberts commented 3 years ago

This has to do with TMUX window behaviour. Don't blame them though, drawing images in the terminal doesn't really fall within classic terminal behaviour so it's really hard to plan for it when you are doing a complicated window layout. Unfortunately, I don't think I can fix this with my code.