davidbrochart / jpterm

Jupyter in the terminal.
https://davidbrochart.github.io/jpterm
MIT License
253 stars 5 forks source link

matplotlib suggestion #95

Open cyborgdennett opened 2 months ago

cyborgdennett commented 2 months ago

Hello, cool app, a bit rough. It would be nice to have some sort of matplotlib terminal show. Currently the system completely crashes when running plt.show().

Perhaps you could use something like https://github.com/matrach/matplotlib-terminal

script:

# importing matplotlib module 
from matplotlib import pyplot as plt 

# x-axis values 
x = [5, 2, 9, 4, 7] 

# Y-axis values 
y = [10, 5, 8, 4, 2] 

# Function to plot 
plt.plot(x, y) 

# function to show the plot 
plt.show()

crash log:

╭─────────────────────────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ /home/casper/dev/notebooks/.venv/lib/python3.12/site-packages/txl_notebook_editor/components.py:343 in on_key                                                                                                                                            │
│                                                                                                                                                                                                                                                          │
│   340 │   │   │   │   │   │   │   }                                                            ╭──────────────────────────────────── locals ────────────────────────────────────╮                                                                        │
│   341 │   │   │   │   │   │   )                                                                │ event = Key(key='ctrl+e', character='\x05', name='ctrl_e', is_printable=False) │                                                                        │
│   342 │   │   │   │   else:                                                                    │  self = NotebookEditor()                                                       │                                                                        │
│ ❱ 343 │   │   │   │   │   await self.kernel.execute(self.current_cell.ycell)                   ╰────────────────────────────────────────────────────────────────────────────────╯                                                                        │
│   344 │   │   elif event.key == Keys.ControlR:                                                                                                                                                                                                           │
│   345 │   │   │   event.stop()                                                                                                                                                                                                                           │
│   346 │   │   │   if self.kernel:                                                                                                                                                                                                                        │
│                                                                                                                                                                                                                                                          │
│ /home/casper/dev/notebooks/.venv/lib/python3.12/site-packages/txl_local_kernels/components.py:21 in execute                                                                                                                                              │
│                                                                                                                                                                                                                                                          │
│   18 │   │   self.kernel = KernelDriver(kernel_name, comm_handlers=self.comm_handlers)        ╭─────────────────────────────────── locals ───────────────────────────────────╮                                                                           │
│   19 │                                                                                        │  self = <txl_local_kernels.components.LocalKernels object at 0x7fd1f0395f10> │                                                                           │
│   20 │   async def execute(self, ycell: Map):                                                 │ ycell = <pycrdt._map.Map object at 0x7fd1f0107aa0>                           │                                                                           │
│ ❱ 21 │   │   await self.kernel.execute(ycell)                                                 ╰──────────────────────────────────────────────────────────────────────────────╯                                                                           │
│   22                                                                                                                                                                                                                                                     │
│   23                                                                                                                                                                                                                                                     │
│   24 class LocalKernelspecs(Kernelspecs):                                                                                                                                                                                                                │
│                                                                                                                                                                                                                                                          │
│ /home/casper/dev/notebooks/.venv/lib/python3.12/site-packages/txl_kernel/driver.py:154 in execute                                                                                                                                                        │
│                                                                                                                                                                                                                                                          │
│   151 │   │   │   │   │   del self.execute_requests[msg_id]                                                                                                                                                                                              │
│   152 │   │   │   │   │   error_message = f"Kernel didn't respond in {timeout} seconds"                                                                                                                                                                  │
│   153 │   │   │   │   │   raise RuntimeError(error_message)                                                                                                                                                                                              │
│ ❱ 154 │   │   │   │   await self._handle_outputs(ycell["outputs"], msg)                                                                                                                                                                                  │
│   155 │   │   │   │   if (                                                                                                                                                                                                                               │
│   156 │   │   │   │   │   (msg["header"]["msg_type"] == "status"                                                                                                                                                                                         │
│   157 │   │   │   │   │   and msg["content"]["execution_state"] == "idle")                                                                                                                                                                               │
│                                                                                                                                                                                                                                                          │
│ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────── locals ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮            │
│ │              code = '# importing matplotlib module \rfrom matplotlib import pyplot as plt \r \r# x-axis '+160                                                                                                                             │            │
│ │           content = {'code': '# importing matplotlib module \rfrom matplotlib import pyplot as plt \r \r# x-axis '+160, 'silent': False}                                                                                                  │            │
│ │          deadline = inf                                                                                                                                                                                                                   │            │
│ │               msg = {                                                                                                                                                                                                                     │            │
│ │                     │   'header': {                                                                                                                                                                                                       │            │
│ │                     │   │   'msg_id': '1b5d9dce-a214ee437226befd49abc2f0_37286_13',                                                                                                                                                       │            │
│ │                     │   │   'msg_type': 'display_data',                                                                                                                                                                                   │            │
│ │                     │   │   'username': 'casper',                                                                                                                                                                                         │            │
│ │                     │   │   'session': '1b5d9dce-a214ee437226befd49abc2f0',                                                                                                                                                               │            │
│ │                     │   │   'date': datetime.datetime(2024, 6, 30, 21, 24, 33, 63008, tzinfo=tzutc()),                                                                                                                                    │            │
│ │                     │   │   'version': '5.3'                                                                                                                                                                                              │            │
│ │                     │   },                                                                                                                                                                                                                │            │
│ │                     │   'msg_id': '1b5d9dce-a214ee437226befd49abc2f0_37286_13',                                                                                                                                                           │            │
│ │                     │   'msg_type': 'display_data',                                                                                                                                                                                       │            │
│ │                     │   'parent_header': {                                                                                                                                                                                                │            │
│ │                     │   │   'date': datetime.datetime(2024, 6, 30, 21, 24, 32, 560643, tzinfo=tzutc()),                                                                                                                                   │            │
│ │                     │   │   'msg_id': 'c3e4b6bc665c4bdf9c3f4d18efcb9369_2',                                                                                                                                                               │            │
│ │                     │   │   'msg_type': 'execute_request',                                                                                                                                                                                │            │
│ │                     │   │   'session': 'c3e4b6bc665c4bdf9c3f4d18efcb9369',                                                                                                                                                                │            │
│ │                     │   │   'username': '',                                                                                                                                                                                               │            │
│ │                     │   │   'version': '5.3'                                                                                                                                                                                              │            │
│ │                     │   },                                                                                                                                                                                                                │            │
│ │                     │   'metadata': {},                                                                                                                                                                                                   │            │
│ │                     │   'content': {                                                                                                                                                                                                      │            │
│ │                     │   │   'data': {'text/plain': '<Figure size 640x480 with 1 Axes>', 'image/png': 'iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGli'+28772},                                           │            │
│ │                     │   │   'metadata': {},                                                                                                                                                                                               │            │
│ │                     │   │   'transient': {}                                                                                                                                                                                               │            │
│ │                     │   },                                                                                                                                                                                                                │            │
│ │                     │   'buffers': []                                                                                                                                                                                                     │            │
│ │                     }                                                                                                                                                                                                                     │            │
│ │            msg_id = 'c3e4b6bc665c4bdf9c3f4d18efcb9369_2'                                                                                                                                                                                  │            │
│ │              self = <txl_local_kernels.driver.KernelDriver object at 0x7fd1f03db440>                                                                                                                                                      │            │
│ │           timeout = inf                                                                                                                                                                                                                   │            │
│ │ wait_for_executed = True                                                                                                                                                                                                                  │            │
│ │             ycell = <pycrdt._map.Map object at 0x7fd1f0107aa0>                                                                                                                                                                            │            │
│ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯            │
│                                                                                                                                                                                                                                                          │
│ /home/casper/dev/notebooks/.venv/lib/python3.12/site-packages/txl_kernel/driver.py:202 in _handle_outputs                                                                                                                                                │
│                                                                                                                                                                                                                                                          │
│   199 │   │   │   outputs.append(                                                                                                                                                                                                                        │
│   200 │   │   │   │   {                                                                                                                                                                                                                                  │
│   201 │   │   │   │   │   "data": content["data"],                                                                                                                                                                                                       │
│ ❱ 202 │   │   │   │   │   "execution_count": content["execution_count"],                                                                                                                                                                                 │
│   203 │   │   │   │   │   "metadata": {},                                                                                                                                                                                                                │
│   204 │   │   │   │   │   "output_type": msg_type,                                                                                                                                                                                                       │
│   205 │   │   │   │   }                                                                                                                                                                                                                                  │
│                                                                                                                                                                                                                                                          │
│ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────── locals ─────────────────────────────────────────────────────────────────────────────────────────────────────────────╮                     │
│ │  content = {'data': {'text/plain': '<Figure size 640x480 with 1 Axes>', 'image/png': 'iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGli'+28772}, 'metadata': {}, 'transient': {}}                 │                     │
│ │      msg = {                                                                                                                                                                                                                     │                     │
│ │            │   'header': {                                                                                                                                                                                                       │                     │
│ │            │   │   'msg_id': '1b5d9dce-a214ee437226befd49abc2f0_37286_13',                                                                                                                                                       │                     │
│ │            │   │   'msg_type': 'display_data',                                                                                                                                                                                   │                     │
│ │            │   │   'username': 'casper',                                                                                                                                                                                         │                     │
│ │            │   │   'session': '1b5d9dce-a214ee437226befd49abc2f0',                                                                                                                                                               │                     │
│ │            │   │   'date': datetime.datetime(2024, 6, 30, 21, 24, 33, 63008, tzinfo=tzutc()),                                                                                                                                    │                     │
│ │            │   │   'version': '5.3'                                                                                                                                                                                              │                     │
│ │            │   },                                                                                                                                                                                                                │                     │
│ │            │   'msg_id': '1b5d9dce-a214ee437226befd49abc2f0_37286_13',                                                                                                                                                           │                     │
│ │            │   'msg_type': 'display_data',                                                                                                                                                                                       │                     │
│ │            │   'parent_header': {                                                                                                                                                                                                │                     │
│ │            │   │   'date': datetime.datetime(2024, 6, 30, 21, 24, 32, 560643, tzinfo=tzutc()),                                                                                                                                   │                     │
│ │            │   │   'msg_id': 'c3e4b6bc665c4bdf9c3f4d18efcb9369_2',                                                                                                                                                               │                     │
│ │            │   │   'msg_type': 'execute_request',                                                                                                                                                                                │                     │
│ │            │   │   'session': 'c3e4b6bc665c4bdf9c3f4d18efcb9369',                                                                                                                                                                │                     │
│ │            │   │   'username': '',                                                                                                                                                                                               │                     │
│ │            │   │   'version': '5.3'                                                                                                                                                                                              │                     │
│ │            │   },                                                                                                                                                                                                                │                     │
│ │            │   'metadata': {},                                                                                                                                                                                                   │                     │
│ │            │   'content': {                                                                                                                                                                                                      │                     │
│ │            │   │   'data': {'text/plain': '<Figure size 640x480 with 1 Axes>', 'image/png': 'iVBORw0KGgoAAAANSUhEUgAAAh8AAAGdCAYAAACyzRGfAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGli'+28772},                                           │                     │
│ │            │   │   'metadata': {},                                                                                                                                                                                               │                     │
│ │            │   │   'transient': {}                                                                                                                                                                                               │                     │
│ │            │   },                                                                                                                                                                                                                │                     │
│ │            │   'buffers': []                                                                                                                                                                                                     │                     │
│ │            }                                                                                                                                                                                                                     │                     │
│ │ msg_type = 'display_data'                                                                                                                                                                                                        │                     │
│ │  outputs = <pycrdt._array.Array object at 0x7fd1f0463ef0>                                                                                                                                                                        │                     │
│ │     self = <txl_local_kernels.driver.KernelDriver object at 0x7fd1f03db440>                                                                                                                                                      │                     │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯                     │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'execution_count'

PS. would be nice to have commandline functionality to go straight to a file, for example jpterm file.ipynb