0

In a windows remote desktop session I am using MobaXTerm to connect to a server, I work into a docker session, I run the following python script from bash terminal

import matplotlib   
from  IPython import display
from matplotlib import pyplot as plt
import numpy as np

import pathlib
import shutil
import tempfile

logdir = pathlib.Path(tempfile.mkdtemp())/"tensorboard_logs"
shutil.rmtree(logdir, ignore_errors=True)

gz = tf.keras.utils.get_file('HIGGS.csv.gz', 'http://mlphysics.ics.uci.edu/data/higgs/HIGGS.csv.gz')
FEATURES = 28
ds = tf.data.experimental.CsvDataset(gz,[float(),]*(FEATURES+1), compression_type="GZIP")

def pack_row(*row):
  label = row[0]
  features = tf.stack(row[1:],1)
  return features, label

packed_ds = ds.batch(10000).map(pack_row).unbatch()

for features,label in packed_ds.batch(1000).take(1):
  print(features[0])
  plt.hist(features.numpy().flatten(), bins = 101)

plt.show(block=True)

I tried as in Show matplotlib plots (and other GUI) in Ubuntu (WSL1 & WSL2) to do

sudo apt-get update

sudo apt-get install python3.6-tk 

pip install matplotlib 

export DISPLAY=localhost:0.0

I also added the headers

import tkinter

matplotlib.use('Agg')

I get no error but the plot won't show

I will favor a solution showing directly the plot when running the script, as an alternative, saving the plot to pdf and viewing it later.

EDIT: set the DISPLAY as

export DISPLAY=`grep -oP "(?<=nameserver ).+" /etc/resolv.conf`:0.0

and now get the following warning

overfit_underfit.py:43: UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
  plt.show(block=True)

Changed the backend to pdf and could successfully save plot to a file, still need to find a pdf viewer.

kiriloff
  • 24,401
  • 34
  • 141
  • 212

0 Answers0