0

Question:

I am having an issue where I am running a diagnostic script on a headless virt machine. In the code I am generating a set of plots relating to individual objects (containing target data). Calling ax.plot_date(x_vals, y_vals) is causing subplots to envoke tcl for display when there is no display available causing an error (see error below).

I would like to use same code, but not generate a plot to display and finally save fig.savefig(filepath). Any and all assistance would be much appreciated!

I am even open to alternate more efficient methods so feel free to provide that as well.

Code Example:

import matplotlib.pyplot as plt
from matplotlib.dates import drange
from datetime import timedelta

# Code...    

# Setup
delta = timedelta(minutes=1)
dates = drange(requested_start, requested_end, delta)

for obj in obj_set:
    # Create Plot
    fig, ax = plt.subplots()
    fig.suptitle('Title', fontsize=10)
    plt.xlabel('Time', fontsize=10)
    ax.set_xlim(dates[0], dates[-1])
    ax.fmt_xdata = DateFormatter('%Y-%m-%d %H:%M:%S')
    ax.plot_date(dates, obj.data_set) #Here is command that I would like assistance
    fig.autofmt_xdate()

    # Setup file information local storage
    file_name = '%s.png' % (self.name)
    file_path = os.path.join(outdir, 'plots', file_name)
    fig.savefig(file_path)
    plt.close(fig)

Error Received:

TclError: no display name and no $DISPLAY environment variable
SMan23
  • 1
  • 2
  • 1
    I think this should give you the solution: http://stackoverflow.com/questions/2801882/generating-a-png-with-matplotlib-when-display-is-undefined So you need to use a "headless" backend. – hitzg Mar 17 '15 at 11:20
  • Use use the `Agg` backend. – tacaswell Mar 17 '15 at 13:51

0 Answers0