I am writing a code that should graph a simple function, and it temporarily works, but I keep encountering this cycle of problems when I restart my computer:
- The first time I try running the code, it doesn't send out any errors, but neither does it create any graphs.
--> To solve this, I installed Xming and wrote the export DISPLAY=localhost:0.0
command in bash, as suggested by AwokeKnowing in Show matplotlib plots in Ubuntu (Windows subsystem for Linux).
- When I run the code, with the above adjustments, I get the following Error:
_tkinter.TclError: no display name and no $DISPLAY environment variable.
--> To solve this, I add the line of code:
matplotlib.use('Agg')
as proposed by Serenity in _tkinter.TclError: no display name and no $DISPLAY environment variable
- After doing this, and running the code, initially graphs properly. But if I try again another day, it doesn't. The code runs normally, but no graph is displayed.
--> To make it work, I remove the line of code:
matplotlib.use('Agg')
And by doing this, the code graphs again.
Then, when I restart my computer, the sequence of problems starts all over again.
Does anyone know what I'm doing wrong? I am very new with using Python, so it is very possible that I am missing something obvious.
Here are the relevant parts of my code:
#Imports
import matplotlib
import matplotlib.pyplot as ply
from dolfin import *
import numpy as np
from mshr import *
import math
from math import exp
plt.plot(tiemporeal,fcmM1)
plt.xlabel('Tiempo')
plt.ylabel('Resistencia')
plt.show()
Thanks a lot, and sorry for possible formatting mistakes.
PS. I am using Python3 on Ubuntu.