Matplotlib中的所有后端都失败并给我一个TypeError:'数字'是一个未知的关键字参数

时间:2017-02-09 15:16:33

标签: python matplotlib backend figure

我一直在运行一个脚本来创建一段时间的子图,现在没有更改的脚本有一个TypeError:'数字'是一个未知的关键字参数。最初我从来没有使用过后端,但由于这个错误,我已经尝试了所有我能找到的,但没有一个能解决这个问题。 我的代码如下:

import matplotlib
matplotlib.rcParams['backend'] = "Qt4Agg"  # e.g.
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

cluster = 1
title = 'TimeSeries_Plot_Spring_' + str(cluster) 
A_data = pd.read_csv('TimeSeries/Spring_TimeSeries_DaAn_ERA_1979-  2012_vF.csv', index_col = 1)
p_data = pd.read_csv('TimeSeries/prob_Spring_TimeSeries_DaAn_ERA_1979-2012_vF.csv', index_col = 1)

place = 1
k = 10 #number of clusters

for i in range (1,k+1):
    A = A_data.loc[place] #select one row of data per time
    p = p_data.loc[place]

    fig, ax1 = plt.subplots()   
    plt.title('Time Series Daily Anomalies Spring: Cluster ' + str(cluster))
    plt.hlines(y=0, xmin=0, xmax=2012, linestyle = '--', zorder=10 )
    ax2 = ax1.twinx() #reproduce a second y-axis for the probability data

    p.plot(kind = 'bar', label = 'percent of days', ax=ax2, color = 'lightgrey', align = 'center')
    ax2.set_ylim([0, 60])
    ax2.set_ylabel('days (%)', color = 'black')

    ax2.set_zorder(1)   

    A.plot( label = 'Flooded Area (km2)', ax = ax1)
    ax1.set_ylim([-40, 30])
    ax1.set_ylabel(ylabel = 'Flooded Area (km2)', color = 'blue')
    ax1.set_zorder(2)
    ax1.set_axis_bgcolor('None') #otherwise the bars disappear

    fig.canvas.draw()

    visible_labels = [lab for lab in ax1.get_xticklabels() if lab.get_visible() is True and lab.get_text() != '']
    plt.setp(visible_labels[1::2], visible=False) 

    for tick in ax1.xaxis.get_ticklabels():
        tick.set_fontsize('small')
        tick.set_rotation(65) #otherwise the years cannot be read

    plt.tight_layout()    
    place += 1
    title = 'TimeSeries_Plot_Spring_' + str(cluster)
    cluster += 1
    plt.savefig('Cluster_Plots/' + title + '.png')

plt.show()

我收到的错误如下:

TypeError                                 Traceback (most recent call last)
<ipython-input-21-b55e1369fcaa> in <module>()
 35
 36     #plt.figure(figsize=(10,7.5))
---> 37     fig, ax1 = plt.subplots()
 38     plt.title('Time Series Daily Anomalies Spring: Cluster ' + str(cluster))
 39     plt.hlines(y=0, xmin=0, xmax=2012, linestyle = '--', zorder=10 )

/p/system/packages/anaconda/2.3.0/lib/python2.7/site-packages/matplotlib/pyplot.pyc in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)
1175         gridspec_kw = {}
1176
-> 1177     fig = figure(**fig_kw)
1178     gs = GridSpec(nrows, ncols, **gridspec_kw)
1179

/p/system/packages/anaconda/2.3.0/lib/python2.7/site-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525                                         frameon=frameon,
526                                         FigureClass=FigureClass,
--> 527                                         **kwargs)
528
529         if figLabel:

/p/system/packages/anaconda/2.3.0/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.pyc in new_figure_manager(num, *args, **kwargs)
 41     FigureClass = kwargs.pop('FigureClass', Figure)
 42     thisFig = FigureClass(*args, **kwargs)
---> 43     return new_figure_manager_given_figure(num, thisFig)
 44
 45

/p/system/packages/anaconda/2.3.0/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.pyc in new_figure_manager_given_figure(num, figure)
 48     Create a new figure manager instance for the given figure.
 49     """
---> 50     canvas = FigureCanvasQTAgg(figure)
 51     return FigureManagerQT(canvas, num)
 52

/p/system/packages/anaconda/2.3.0/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.pyc in __init__(self, figure)
214         if DEBUG:
215             print('FigureCanvasQtAgg: ', figure)
--> 216         super(FigureCanvasQTAgg, self).__init__(figure=figure)
217         self._drawRect = None
218         self.blitbox = None

/p/system/packages/anaconda/2.3.0/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.pyc in __init__(self, figure)
 63
 64     def __init__(self, figure):
---> 65         super(FigureCanvasQTAggBase, self).__init__(figure=figure)
 66         self._agg_draw_pending = False
 67

/p/system/packages/anaconda/2.3.0/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.pyc in __init__(self, figure)
237         # The need for this change is documented here
238         #    http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html#cooperative-multi-inheritance
--> 239         super(FigureCanvasQT, self).__init__(figure=figure)
240         self.figure = figure
241         self.setMouseTracking(True)

TypeError: 'figure' is an unknown keyword argument

有人可以帮帮我吗? 谢谢!

0 个答案:

没有答案