Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Sep 18, 2024 · 1 comment

Comments

@strawberry098
Copy link

strawberry098 commented Sep 18, 2024

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
Copy link
Member

ghuls commented Sep 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants