简体   繁体   English

Matplotlib 数字未在 GitHub CodeSpaces 中生成

[英]Matplotlib figures not generating in GitHub CodeSpaces

I just started using Codespaces.我刚开始使用代码空间。 In my python file I have this code:在我的 python 文件中,我有以下代码:

import matplotlib.pyplot as plt
import pandas as pd 

print("Hello")

titanic_data = pd.read_csv("https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv")
titanic_data = titanic_data[titanic_data['Age'].notnull()]
titanic_data['Fare'] = titanic_data['Fare'].fillna(titanic_data['Fare'].mean())
titanic_data = titanic_data.drop_duplicates()
plt.scatter(titanic_data['Age'], titanic_data['Fare'])
plt.show()

print("Goodbye")

When I run this on my local machine, this works perfectly.当我在我的本地机器上运行它时,它工作得很好。 I can see the console logs, and the figure appears as a new window:我可以看到控制台日志,图中显示为新的 window:

局部环境中绘制的图形

However, when I run this in Codespaces, I can see all of the code running without any errors, but it does not show the figure.但是,当我在 Codespaces 中运行它时,我可以看到所有代码都在运行,没有任何错误,但它没有显示图形。 Is this a known limitation or a feature that is not yet supported?这是已知限制还是尚不支持的功能? Is there another way I can plot figures in Codespaces?还有其他方法可以在 Codespaces 中显示 plot 数字吗?

They mention this in the docs docs :他们在文档文档中提到了这一点:

The default container image that's used by GitHub Codespaces includes a set of machine learning libraries that are preinstalled in your codespace. GitHub Codespaces 使用的默认容器映像包括一组预安装在您的代码空间中的机器学习库。 For example, Numpy, pandas, SciPy, Matplotlib, seaborn, scikit-learn, Keras, PyTorch, Requests, and Plotly. For example, Numpy, pandas, SciPy, Matplotlib, seaborn, scikit-learn, Keras, PyTorch, Requests, and Plotly.

It sounds like it should be supported out of the box.听起来应该开箱即用。 Is additional configuration required?是否需要额外配置?

Based on the experimentation I have done thus far, plotting these diagrams as one would do in a local dev environment is not (yet?) possible.根据我迄今为止所做的实验,像在本地开发环境中那样绘制这些图表是不可能的(目前?)。

For this specific case, the next best solution was to create a new GitHub Codespace from this repo: https://github.com/education/codespaces-teaching-template-py对于这个特定案例,下一个最佳解决方案是从这个 repo 创建一个新的 GitHub 代码空间: https://github.com/education/codespaces-teaching-template-py

克隆到代码空间

Once the repo has been cloned into the Codespace, navigate to an existing .ipynb file or create your own.将存储库克隆到 Codespace 后,导航到现有的.ipynb文件或创建您自己的文件。

Inside there you'll be able to run chunks of custom code and plot figures.在里面,您将能够运行自定义代码块和 plot 数字。

Codespace 中的 Matplotlib

The big limitation I see is that the figure cannot be interacted with the same way that one would be able to on a local machine (zooming, panning, etc).我看到的最大限制是无法以与在本地计算机上能够进行的相同方式(缩放、平移等)交互图形。

As always, don't forget to shut your Codespace down when you're done using it!与往常一样,不要忘记在使用完 Codespace 后将其关闭!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM