tomgoldstein / loss-landscape

Code for visualizing the loss landscape of neural nets
MIT License
2.72k stars 388 forks source link

Plotting to pdf files #16

Closed wenwei202 closed 5 years ago

wenwei202 commented 5 years ago

We have some nodes which only support command interface, and there is no GUI display. If we run the code, then we will get

_tkinter.TclError: no display name and no $DISPLAY environment variable

Can we save figures just into files such as pdf files?

wenwei202 commented 5 years ago

Using pdf backend solves my issue.

diff --git a/plot_1D.py b/plot_1D.py
index 9a0d35d..84c263f 100644
--- a/plot_1D.py
+++ b/plot_1D.py
@@ -1,6 +1,8 @@
 """
     1D plotting routines
 """
+import matplotlib
+matplotlib.use('pdf')

 from matplotlib import pyplot as pp
 import h5py
diff --git a/plot_2D.py b/plot_2D.py
index 415d5d6..b8b9c3a 100644
--- a/plot_2D.py
+++ b/plot_2D.py
@@ -1,6 +1,8 @@
 """
     2D plotting funtions
 """
+import matplotlib
+matplotlib.use('pdf')

 from mpl_toolkits.mplot3d import Axes3D
 from matplotlib import pyplot as plt
diff --git a/plot_surface.py b/plot_surface.py
index 6d68574..eae53bc 100755
--- a/plot_surface.py
+++ b/plot_surface.py
@@ -3,6 +3,8 @@
     Usage example:
     >>  python plot_surface.py --x=-1:1:101 --y=-1:1:101 --model resnet56 --cuda
 """
+import matplotlib
+matplotlib.use('pdf')
 import argparse
 import copy
 import h5py