0

So I am trying to plot a 3d chart using mplot3d with matplotlib. Code as following:

# generate the graph
# vols is a 2D array indexed by [maturity, strike].
def DrawGraph(self, strikes, maturities, vols):       
    import matplotlib.dates as dates
    import matplotlib.pyplot as pyplot

    # prepare data
    Y = dates.date2num(maturities)
    X, Y = numpy.meshgrid(strikes, Y)

    # plot
    fig = pyplot.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.plot_wireframe(X, Y, vols)
    pyplot.show()

Where maturities and strikes are 1D arrays, and vols is a 2D array with proper size. Everything runs proper and all data are valid. However, I got a totally blank window with nothing but gray background.

Anyone can give me some hints of what's going on? I suspect the version of matplotlib isn't right but not sure how to check it.

Thanks in advance.

Alex Suo
  • 2,977
  • 1
  • 14
  • 22
  • In `ipython` (or just the python console if you prefer), try `import matplotlib; matplotlib.__version__` to get the version information. Or you can use the one-liner: `python -c 'import matplotlib; print matplotlib.__version__'` – jmetz Jul 04 '13 at 09:35

2 Answers2

0

In the version of matplotlib I have (1.2.1) the projection="3d" will raise an error unless you also include:

from mpl_toolkits.mplot3d import Axes3D

The only thing I can't check is the line

Y = dates.date2num(maturities)

As I am unfamiliar with what data type date2num expects, do you have any sample data?

Other than this everything works fine for me

Greg
  • 11,654
  • 3
  • 44
  • 50
0

What about

matplotlib.pyplot.ioff()

That solved my "nothing but gray background"-problem with mplot3d.

Finn Årup Nielsen
  • 6,130
  • 1
  • 33
  • 43