简体   繁体   中英

mplot3d gives blank graph but no error

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.

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

What about

matplotlib.pyplot.ioff()

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM