英文:
<Figure size 800x800 with 0 Axes> when using plt.show() Jupyter Notebook
问题
以下是您要翻译的内容:
我正在尝试参加CISCO IoT Big Data课程,我必须在Jupyter Notebook中使用Python内核进行实验。尽管我已经完全按照实验中显示的方式操作,但我仍然看不到图表。它只是显示:<Figure size 800x800 with 0 Axes>
以下是代码:
%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from ipywidgets import interact
def scatter_view(x, y, z, azim, elev):
# 初始化图和坐标轴
fig = plt.figure(figsize=(8, 8))
ax = Axes3D(fig)
# 计算散点图
ax.scatter(x, y, z)
ax.set_xlabel('D rate (Mbit/s)', fontsize=16)
ax.set_ylabel('U rate (Mbit/s)', fontsize=16)
ax.set_zlabel('P rate (1/s)', fontsize=16)
ax.azim = azim
ax.elev = elev
xi = df_rates['download_rate']
yi = df_rates['upload_rate']
zi = df_rates['ping_rate']
interact(lambda azim, elev: scatter_view(xi, yi, zi, azim, elev),
azim=(0, 90), elev=(0, 90))
plt.show()
我已经尝试更改图形大小,在导入之前或之后使用matplotlib。我在互联网上找不到解决方案。我对这个概念非常陌生,如果有人能解释为什么它不显示,我将不胜感激。谢谢!
英文:
I am trying to do a CISCO IoT Big Data course and i have to do a lab in jupyter notebook with Python kernel. Still i can't see the figure even if i did exactly like it shows me in the lab. It simply shows me: <Figure size 800x800 with 0 Axes>
Here is the code:
%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from ipywidgets import interact
def scatter_view(x, y, z, azim, elev):
# Init figure and axes
fig = plt.figure(figsize=(8, 8))
ax = Axes3D(fig)
# Compute scatter plot
ax.scatter(x, y, z)
ax.set_xlabel('D rate (Mbit/s)', fontsize=16)
ax.set_ylabel('U rate (Mbit/s)', fontsize=16)
ax.set_zlabel('P rate (1/s)', fontsize=16)
ax.azim = azim
ax.elev = elev
xi = df_rates['download_rate']
yi = df_rates['upload_rate']
zi = df_rates['ping_rate']
interact(lambda azim, elev: scatter_view(xi, yi, zi, azim, elev),
azim=(0, 90), elev=(0, 90))
plt.show()
I have tried to change figure size, use matplotlib in line before or after the import. I couldn't find a solution on the internet. I'm pretty new to this concept, if anyone can explain to me why it doesn't show. Thanks!
答案1
得分: 0
Replace the line
ax = Axes3D(fig)
with
ax = fig.add_subplot(projection='3d')
See the documentation:
3D Axes (of class Axes3D) are created by passing the projection="3d" keyword argument to Figure.add_subplot:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
Also quoting the api documentation for Axis3D
:
Note
As a user, you do not instantiate Axes directly, but use Axes creation methods instead; e.g. from pyplot or Figure: subplots, subplot_mosaic or Figure.add_axes.
英文:
Replace the line
ax = Axes3D(fig)
with
ax = fig.add_subplot(projection='3d')
See the documentation:
> 3D Axes (of class Axes3D) are created by passing the projection="3d" keyword argument to Figure.add_subplot:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
Also quoting the api documentation for Axis3D
:
> Note
>
> As a user, you do not instantiate Axes directly, but use Axes creation methods instead; e.g. from pyplot or Figure: subplots, subplot_mosaic or Figure.add_axes.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论