Here is a complete working example.
import matplotlib.pyplot as plt
# Create your data
x_data = [1,2,3,4,5]
y_data = [5,4,2,3,1]
# Create a figure to hold the plot
fig = plt.figure(figsize=(5,4)) # if you don't define figsize, it should
# still work, depending on your configs
# Create a set of set of axes on the plot (as you might have multiple subplots)
# This says put in an axis at position 1 as if the figure were a 1 by 1 grid
ax = fig.add_subplot(1,1,1)
# Make the scatter plot
ax.scatter(x,y)
# Save the plot
fig.savefig("foo.png")
If this doesn't work, what's probably happening is that your matplotlib is using X somewhere in its backend. You can force it to not by having the following at the top:
import matplotlib
# The important line!
matplotlib.use('Agg')
import matplotlib.pyplot as plt
And do it in that order.