[Matplotlib-users] What changes from matplotlib 1.3.1 to matplotlib 1.5.1 break the following code?

Jacob Barhak jacob.barhak at gmail.com
Thu Mar 24 12:52:48 EDT 2016


Sorry Paul,

The 5 lines with DB in them should ignored. So please comment the 5 lines
after the line that things broke in - it is a file that MIST uses and is
not needed for this script. You may also make sure the is a Temp sub
directory below the execution path since the pdf filename should be stored
there.

Yet after making those fixes, you will find out that the script works on
matplotlib 1.3.1 and breaks on matplotlib 1.5.1. with the following error:

Traceback (most recent call last):
  File "PlotGeneration_Mod.py", line 21, in <module>
    TheLegend = HandleAxes.legend(LineHandles, LabelHandles, 0, prop =
HandleSma
llerFont, handlelength = 2.0/1.0)
  File "C:\Anaconda\lib\site-packages\matplotlib\axes\_axes.py", line 536,
in le
gend
    raise TypeError('Invalid arguments to legend.')
TypeError: Invalid arguments to legend.


Hopefully this behavior can be explained with changes made.

I am unsure I wish to upgrade the code, I am considering tow solutions 1)
keeping the old matplotlib version, 2) making some code changes to match
the newer version.

Your explanation will help me decide on the best solution.


                 Jacob

On Thu, Mar 24, 2016 at 10:45 AM, Paul Hobson <pmhobson at gmail.com> wrote:

> Can you trim this down to a reproducible example?
>
> It's hard to debug a "this doesn't work" question when I can't get past
> the imports ("import DataDef as DB")
>
> At the very least, could you tell use where the error is occurring and
> what the error message is?
> -paul
>
> On Thu, Mar 24, 2016 at 1:02 AM, Jacob Barhak <jacob.barhak at gmail.com>
> wrote:
>
>> Greetings,
>>
>> Are there specific new changes in matplotlib 1.5.1 that break previous
>> code?
>>
>> Below is a script that works nicely with matplotlib 1.3.1 and breaks on
>> matplotlib 1.5.1 that comes with the new anaconda on Windows.
>>
>> I am trying to decide if a downgrade of the matplotlib version is the
>> best solution or is there another simple fix that will make the code work
>> again?
>>
>> Note that this is code generated by the MIST system test code, so do not
>> look for logical output - the current goal is just to pass the test by not
>> breaking on any commands.
>>
>> I will appreciate your insight.
>>
>>               Jacob
>>
>>
>> ############# Code that Breaks with 1.5.1 ##############
>>
>> from __future__ import division
>> import matplotlib
>> matplotlib.use('PDF')
>> import matplotlib.pyplot as plt
>> import matplotlib.font_manager
>> import matplotlib.backends.backend_pdf
>> import DataDef as DB
>> Inf = DB.Inf
>> NaN = DB.NaN
>> inf = DB.inf
>> nan = DB.nan
>> HandlePDF =
>> matplotlib.backends.backend_pdf.PdfPages('Temp\SelectedAssembledPlots.pdf')
>> HandleFigure = plt.figure()
>> HandleAxes = HandleFigure.add_subplot(111)
>> DefaultLegendFontSize =
>> matplotlib.font_manager.FontProperties(size=matplotlib.rcParams['legend.fontsize']).get_size_in_points()
>> # New plot sequence
>> HandleAxes.clear()
>> HandleAxes.clear()
>> HandleAxes.set_title('Age - Avg All')
>> HandleAxes.set_xlabel('Time')
>> HandleAxes.plot( [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3] ,[None,
>> 30.0, None, 30.0, None, 31.0, None, 31.0, 32.0, 32.0, 32.0, 32.0, 33.0,
>> 33.0, 33.0, 33.0], 'ko-' , label = 'File 1')
>> HandleAxes.plot( [] ,[], 'k:' , label = 'File 2')
>> HandleSmallerFont = matplotlib.font_manager.FontProperties(size=
>> DefaultLegendFontSize*1.0 )
>> LineHandles, LabelHandles = HandleAxes.get_legend_handles_labels()
>> TheLegend = HandleAxes.legend(LineHandles, LabelHandles, 0, prop =
>> HandleSmallerFont, handlelength = 2.0/1.0)
>> TheLegend.get_frame().set_alpha(0.5)
>> HandlePDF.savefig(HandleFigure)
>> HandleAxes.clear()
>> HandleAxes.set_title("""Create Plots Warning: No parameter entry :
>> ('Alive', 'Avg All', '')""")
>> HandlePDF.savefig(HandleFigure)
>> HandleAxes.clear()
>> HandleAxes.set_title(' - Rec Count')
>> HandleAxes.set_xlabel('Time')
>> HandleAxes.plot( [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3] ,[None,
>> 900, None, 1000, None, 900, None, 900, 63, 835, 772, 835, 61, 772, 711,
>> 772], 'ko-' , label = 'File 1')
>> HandleAxes.plot( [] ,[], 'k:' , label = 'File 2')
>> HandleSmallerFont = matplotlib.font_manager.FontProperties(size=
>> DefaultLegendFontSize*1.0 )
>> LineHandles, LabelHandles = HandleAxes.get_legend_handles_labels()
>> TheLegend = HandleAxes.legend(LineHandles, LabelHandles, 0, prop =
>> HandleSmallerFont, handlelength = 2.0/1.0)
>> TheLegend.get_frame().set_alpha(0.5)
>> HandlePDF.savefig(HandleFigure)
>> # New plot sequence
>> HandleAxes.clear()
>> HandleAxes.set_title("""Create Plots Warning: No parameter entry :
>> ('Alive', 'Avg All', '')""")
>> HandlePDF.savefig(HandleFigure)
>> HandleAxes.plot( [None, 30.0, None, 30.0, None, 31.0, None, 31.0, 32.0,
>> 32.0, 32.0, 32.0, 33.0, 33.0, 33.0, 33.0] ,[None, 900, None, 1000, None,
>> 900, None, 900, 63, 835, 772, 835, 61, 772, 711, 772], 'ko-' , label =
>> 'File 1 - nested record count')
>> HandleAxes.plot( [] ,[], 'k:' , label = 'File 2 - nested record count')
>> HandleSmallerFont = matplotlib.font_manager.FontProperties(size=
>> DefaultLegendFontSize*0.714285714286 )
>> LineHandles, LabelHandles = HandleAxes.get_legend_handles_labels()
>> TheLegend = HandleAxes.legend(LineHandles, LabelHandles, 0, prop =
>> HandleSmallerFont, handlelength = 2.0/0.714285714286)
>> TheLegend.get_frame().set_alpha(0.5)
>> HandlePDF.savefig(HandleFigure)
>> HandleAxes.clear()
>> HandleAxes.set_title("""Create Plots Warning: No parameter entry :
>> ('AnError', 'Avg All', '')""")
>> HandlePDF.savefig(HandleFigure)
>> HandleAxes.clear()
>> HandleAxes.set_title("""Create Plots Warning: No parameter entry :
>> ('Alive', 'AlsoAnError', '')""")
>> HandlePDF.savefig(HandleFigure)
>> HandlePDF.close()
>>
>>
>>
>>
>>
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users at python.org
>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160324/890a7043/attachment.html>


More information about the Matplotlib-users mailing list