Monday, April 18, 2022

Matploblib does not show interactive plots on SciView in PyCharm

I encounter a problem when I plot an interactive plot using Matplotlib in PyCharm. The problem is that it does not show the interactive plot on SciView as it usually does. Although it could be due to the idiomatic way of  my creating python plot, I look for a "cheap" way to fix this since the code successfully creates interactive plots when I run it fron the console outside of PyCharm. The solution tends out to be use a different Matploblib backend. 

In PyCharm's python console, we can determine which Matploblib backend is currently using, e.g.,


>>> import matplotlib
>>> matplotlib.get_backend()
'module://backend_interagg'

>>>

In an OS console, we can determine which Matploblib backend is currently using, e.g.,


>>> import matplotlib
>>> matplotlib.get_backend()
'TkAgg'

>>>

Based on the observations in the above, the solution is to set the Matplotlib backend as the one used by Matplotlib on the OS console, e.g.,



import matplotlib


if __name__ == '__main__':
    matplotlib.use('TkAgg')
    # ...
    # more code ...
    # ...



No comments:

Post a Comment