aertslab / pycisTopic

pycisTopic is a Python module to simultaneously identify cell states and cis-regulatory topics from single cell epigenomics data.
Other
58 stars 12 forks source link

plot_metadata: X11 connection rejected because of wrong authentication / Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running #170

Open strawberry098 opened 2 months ago

strawberry098 commented 2 months ago

I'm getting an error with plot_metadata

import tkinter as tk
import matplotlib
i = 0
while i < 10:
    i += 1
    try:
        matplotlib.use('TkAgg')
        break
    except:
        print(i)
from pycisTopic.clust_vis import (
    find_clusters,
    run_umap,
    run_tsne,
    plot_metadata,
    plot_topic,
    cell_topic_heatmap
)

plot_metadata(
    cistopic_obj1_models,
    reduction_name='UMAP',
    variables='predicted.id.from.act',
    target='cell', 
    text_size=10,
    dot_size=5)

X11 connection rejected because of wrong authentication.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/conda/envs/scenicplus/lib/python3.11/site-packages/pycisTopic/clust_vis.py", line 451, in plot_metadata
    fig = plt.figure(figsize=figsize)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/conda/envs/scenicplus/lib/python3.11/site-packages/matplotlib/_api/deprecation.py", line 454, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/root/conda/envs/scenicplus/lib/python3.11/site-packages/matplotlib/pyplot.py", line 783, in figure
    manager = new_figure_manager(
              ^^^^^^^^^^^^^^^^^^^
  File "/root/conda/envs/scenicplus/lib/python3.11/site-packages/matplotlib/pyplot.py", line 358, in new_figure_manager
    _warn_if_gui_out_of_main_thread()
  File "/root/conda/envs/scenicplus/lib/python3.11/site-packages/matplotlib/pyplot.py", line 336, in _warn_if_gui_out_of_main_thread
    if _get_required_interactive_framework(_get_backend_mod()):
                                           ^^^^^^^^^^^^^^^^^^
  File "/root/conda/envs/scenicplus/lib/python3.11/site-packages/matplotlib/pyplot.py", line 207, in _get_backend_mod
    switch_backend(dict.__getitem__(rcParams, "backend"))
  File "/root/conda/envs/scenicplus/lib/python3.11/site-packages/matplotlib/pyplot.py", line 273, in switch_backend
    raise ImportError(
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running
ghuls commented 2 months ago

Login you your server with ssh -X.

Or don't use import tkinter as tk and matplotlib.use('TkAgg')

import matplotlib

matplotlib.use('Agg')

import matplotlib.pyplot as plt