最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Matplotlib not rendering chart in Jupyter (Conda) - Stack Overflow

programmeradmin5浏览0评论

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.

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.

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

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.

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.

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

Share Improve this question asked Mar 25 at 11:49 jpankninjpanknin 1172 gold badges3 silver badges12 bronze badges 6
  • Never post screenshot of code or logs this is counter productive while wasting resources and preventing the community to help you efficiently. Instead copy paste and format. – jlandercy Commented Mar 25 at 12:08
  • @jlandercy, got it will do in the future. Thank you. – jpanknin Commented Mar 25 at 12:26
  • What happens if you just remove %matplotlib inline like in this very similar question stackoverflow/questions/79366461/…? – Matt Pitkin Commented Mar 25 at 14:37
  • %matplotlib inline is the default now. It is not needed if you aren't switching anything with %matplotlib otherwise. Not sure though why it would need to be removed other than something about your installation seems flawed as it is. You shouldn't need plt.show() that it seems you checked off as solving it if you truly have a fresh working installation. Had you restarted everything before this test? And I mean everything. The entire browser and machine. Also, done a hard refresh on your brower page where the notebook is? (On a MAc in Chrome, Shift + Comand + r does it.) – Wayne Commented Mar 25 at 15:46
  • To make it easy to test what should happen, I suggest using MyBinder sessions for modern Jupyter without needing to touch your own machine. One of the Jupyter developers keeps a fairly up to date offering here. For example, JupyterLab 4.3 on Binder is one of the most recent. Launch that in your browser by hitting 'launch binder'. When the session comes up, open a new notebook and run %pip install numpy matplotlib to install those two packages. Restart the kernel and run the code ... – Wayne Commented Mar 25 at 16:00
 |  Show 1 more comment

1 Answer 1

Reset to default 1

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

发布评论

评论列表(0)

  1. 暂无评论