pythonmatplotlibjupyter-notebookjupyter-lab

Matplotlib not rendering chart in Jupyter (Conda)


I just installed the most recent version of Anaconda (24.11.3). I'm trying to do a simple line chart using matplotlib, but am just getting the text output instead of the actual chart.

Code to render a matplotlib chart

I tried this exact same code in both Jupyter Notebook and JupyterLab (both opened through Anaconda Navigator) and am getting the same text output instead of the chart itself in both.

These are the matplotlib versions that are installed in conda.

matplotlib versions

Anyone have any idea why this is happening and how to fix it?


Solution

  • You are missing plt.show(). Your code returns a Line2D object and that is what the line below the code block states (also mentioning the position in your computer's memory).

    This code works just fine:

    x = np.linspace(-10, 10, 100)
    y = np.sin(x)
    
    plt.plot(x, y, marker="x")
    plt.show()
    

    Note that you can also have interactive plots with %matplotlib notebook