简体   繁体   English

mplot3d给出空白图表,但没有错误

[英]mplot3d gives blank graph but no error

So I am trying to plot a 3d chart using mplot3d with matplotlib. 因此,我试图使用mplot3d和matplotlib绘制3d图表。 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. 其中到期日和执行价格为一维数组,而vols为具有适当大小的二维数组。 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. 我怀疑matplotlib的版本不正确,但不确定如何检查。

Thanks in advance. 提前致谢。

In the version of matplotlib I have (1.2.1) the projection="3d" will raise an error unless you also include: 在matplotlib版本中,我有(1.2.1),除非您同时包含以下内容,否则projection="3d"会引发错误:

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? 由于我不熟悉date2num期望的数据类型,因此您有任何示例数据吗?

Other than this everything works fine for me 除此之外,一切对我来说都很好

What about 关于什么

matplotlib.pyplot.ioff()

That solved my "nothing but gray background"-problem with mplot3d. mplot3d解决了我的“灰色背景”问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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