【发布时间】:2021-04-16 10:49:07
【问题描述】:
我在 jupyter notebook 中绘制散点图,其中包含 2 个单元格
from matplotlib import pyplot as plt
import numpy as np
# Plot single point
# 1st, create a figure
fig = plt.figure()
# then create an 'ax' in this figure
ax = fig.add_subplot(111)
# plot red point at x=7, y=42
ax.scatter(x = [7], y = [42])
和
# Plot multiple points
# create a center
center = (7, 42)
# sample scaled normal distribution
datapoints = 10 * np.random.randn(50, 50)
# re-center data
datapoints[0, :] += center[0]
datapoints[1, :] += center[1]
# plot red point for every data-point
ax.scatter(x = datapoints[0, :], y = datapoints[1, :], color = "red")
plt.show()
第一个单元格返回
而第二个什么都不返回。能否请您详细说明一下这个问题?
更新:我试着把
ax
fig
在第二个单元格中。特别是,
# Plot multiple points
# create a center
center = (7, 42)
# sample scaled normal distribution
datapoints = 10 * np.random.randn(50, 50)
# re-center data
datapoints[0, :] += center[0]
datapoints[1, :] += center[1]
# plot red point for every data-point
ax
fig
ax.scatter(x = datapoints[0, :], y = datapoints[1, :], color = "red")
plt.show()
但运行第二个单元仍然没有返回任何内容。
【问题讨论】:
-
@Mr.T 感谢您添加标签
jupyter-notebook。 -
@user202729 请查看我的更新。
-
“它不起作用”是什么意思?什么行为? (什么都没有出现?)
-
@user202729 更新已更正。什么都没有显示。
标签: python-3.x matplotlib jupyter-notebook scatter-plot