twibiral / obsidian-execute-code

Obsidian Plugin to execute code in a note.
MIT License
984 stars 60 forks source link

Axes3D.plot() missing 2 required positional arguments: 'xs' and 'ys' #260

Open alessandrosantospirito opened 1 year ago

alessandrosantospirito commented 1 year ago

I am not able to render 3d plots. When I execute the same code in the python path I have provided everything works, only in obsidian I can't get it working. image

alessandrosantospirito commented 1 year ago

So I did not find a solution. Maybe it is because the Notebook environment is outdated? A workaround I found was to deactivate the Notebook environment and then it worked.

As a note: I use the python path the python version of a conda environment where I have weverything installed.

alessandrosantospirito commented 1 year ago

It also helped to start matplotlib outside obsidian, which allows the use of interactive components. Here is such an example I found on stackoverflow (Link to the post).

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.widgets import Slider

N = 100

X = np.linspace(0, 20, N)
Y = np.linspace(0, 20, N)
x, y = np.meshgrid(X, Y)
z = np.sin(x) + np.sin(y)

fig = plt.figure()

ax1 = fig.add_axes([0, 0, 1, 0.8], projection = '3d')
ax2 = fig.add_axes([0.1, 0.85, 0.8, 0.1])

s = Slider(ax = ax2, label = 'value', valmin = 0, valmax = 5, valinit = 2)

def update(val):
    value = s.val
    ax1.cla()
    ax1.plot_surface(x, y, z + value, cmap = cm.coolwarm, linewidth = 0, antialiased = False)
    ax1.set_zlim(-2, 7)

s.on_changed(update)
update(0)

plt.show(block=True)
MetaflameDragon commented 2 weeks ago

I encountered the same issue. Running the same code in python interactive (in cmd) opened the 3D plot properly. Likewise, using a 2D plot (fig.add_subplot() instead of fig.add_subplot(projection="3d")) embedded a plot in Obsidian correctly.

I suspect something goes wrong within the embedding integration?