我正在绘制一个图表来观察高斯分布。
代码:
import random
import matplotlib.pyplot as plt
nums = []
mu = 100
sigma = 50
for i in range(100):
temp = random.gauss(mu, sigma)
nums.append(temp)
plt.plot(nums)
plt.show()
但是当我运行它时,会出现错误:
No protocol specified
No protocol specified
Traceback (most recent call last):
File "hello.py", line 12, in <module>
plt.plot(nums, temp)
File "/home/pablo/environments/my_env/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2823, in plot
return gca().plot(
File "/home/pablo/environments/my_env/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2351, in gca
return gcf().gca(**kwargs)
File "/home/pablo/environments/my_env/lib/python3.7/site-packages/matplotlib/pyplot.py", line 730, in gcf
return figure()
File "/home/pablo/environments/my_env/lib/python3.7/site-packages/matplotlib/pyplot.py", line 676, in figure
**kwargs)
File "/home/pablo/environments/my_env/lib/python3.7/site-packages/matplotlib/pyplot.py", line 298, in new_figure_manager
return _backend_mod.new_figure_manager(*args, **kwargs)
File "/home/pablo/environments/my_env/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 3490, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
File "/home/pablo/environments/my_env/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 859, in new_figure_manager_given_figure
window = tk.Tk(className="matplotlib")
File "/usr/lib/python3.7/tkinter/__init__.py", line 2023, in __ init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0"