0

I'm plotting a graph to observe the gaussian distribution.

Code:

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()

but when I run it, error comes with:

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"
Blckknght
  • 100,903
  • 11
  • 120
  • 169
  • Try `plt.savefig('gauss.png')` to save figure. Or, to display try `export DISPLAY=unix$DISPLAY` in a shell. – Parth Shah Jul 25 '20 at 07:49
  • 1
    if you want to display your figure interactively, you can also try to use ``import matplotlib``, then ``matplotlib.use("Qt5Agg")`` or ``matplotlib.use("GTK3Agg")`` **before** importing ``pyplot``, since the error message may come from a configuration error that is Tk specific. – Silmathoron Jul 25 '20 at 09:33
  • Thank you! used `import matplotlib` `matplotlib.use("Qt5Agg")` and it worked! I really appreciate it. – Pablo Escobar Jul 25 '20 at 19:26

0 Answers0