jkall / qgis-midvatten-plugin

Midvatten plugin for QGIS
25 stars 8 forks source link

Matplotlib 'Automatic legend placement' Error #335

Closed mabi38 closed 3 years ago

mabi38 commented 3 years ago

When I ttry creating a time series plot or an XY plot I receive the follwing python error:

Traceback (most recent call last): File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\midvatten_plugin.py", line 138, in self.actionPlotTS.triggered.connect(lambda x: self.plot_timeseries()) File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\tools\utils\common_utils.py", line 1122, in new_func result = func(*args, *kwargs) File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\midvatten_plugin.py", line 811, in plot_timeseries dlg = TimeSeriesPlot(qgis.utils.iface.activeLayer(), self.ms.settingsdict) File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\tools\tsplot.py", line 42, in init self.showtheplot(layer) File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\tools\utils\db_utils.py", line 393, in func_wrapper ret = func(args, *kwargs) File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\tools\tsplot.py", line 103, in showtheplot leg = fig.legend(p, plabel, loc=0)#leg = fig.legend(p, plabel, 'right') File "C:\OSGeo4W\apps\Python39\lib\site-packages\matplotlib\figure.py", line 1958, in legend l = mlegend.Legend(self, handles, labels, extra_args, File "C:\OSGeo4W\apps\Python39\lib\site-packages\matplotlib\legend.py", line 461, in init raise ValueError(

         ValueError: Automatic legend placement (loc='best') not implemented for figure legend.

Did work in the past perfectly, but now? Any idea how to solve the problem? Thanks a lot for helpful hints.

Martin

HenrikSpa commented 3 years ago

This bug is caused by changes in Matplotlib 3.3:

"MatplotlibDeprecationWarning:

Automatic legend placement (loc='best') not implemented for figure legend. Falling back on 'upper right'. This will raise an exception in 3.3."

HenrikSpa commented 3 years ago

@mabi38 Thanks for reporting the bug! I've uploaded version 1.6.7 to QGIS plugin repository. Please try the new version to see if it fixes the error.

Regards, Henrik

mabi38 commented 3 years ago

Unfortunately, it did not fix the problem - as far as I understood another error has been created:

Traceback (most recent call last): File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\tools\tsplot.py", line 106, in showtheplot leg = fig.legend(p, plabel, loc=0) #leg = fig.legend(p, plabel, 'right') File "C:\OSGeo4W\apps\Python39\lib\site-packages\matplotlib\figure.py", line 1958, in legend l = mlegend.Legend(self, handles, labels, *extra_args, File "C:\OSGeo4W\apps\Python39\lib\site-packages\matplotlib\legend.py", line 461, in init raise ValueError( ValueError: Automatic legend placement (loc='best') not implemented for figure legend.

         During handling of the above exception, another exception occurred:

         Traceback (most recent call last):
          File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\midvatten_plugin.py", line 138, in 
          self.actionPlotTS.triggered.connect(lambda x: self.plot_timeseries())
          File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\tools\utils\common_utils.py", line 1122, in new_func
          result = func(*args, **kwargs)
          File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\midvatten_plugin.py", line 811, in plot_timeseries
          dlg = TimeSeriesPlot(qgis.utils.iface.activeLayer(), self.ms.settingsdict)
          File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\tools\tsplot.py", line 43, in __init__
          self.showtheplot(layer)
          File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\tools\utils\db_utils.py", line 393, in func_wrapper
          ret = func(*args, **kwargs)
          File "C:\Users/Martin/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\midvatten\tools\tsplot.py", line 108, in showtheplot
          common_utils.MessagebarAndLog.info(log_msg="""Figure legend didn't work, using axis legend instead, msg: """%str(e))
         TypeError: not all arguments converted during string formatting

TSS-and XY-plots return the same error message. Custom plot is working without any problems.

mabi38 commented 3 years ago

Sorry, I pressed the wrong bottom. Should stay opened.

HenrikSpa commented 3 years ago

I messed up the error message. There is a version 1.6.8 now which should fix it.

mabi38 commented 3 years ago

I guess it is almost done. TS-plot is working. The error mentioned above disappeared. Great! Thank you so much. But trying to create a XY-plot I got this: DB error! SQL causing this error:SELECT meas_cis as 'x', meas_tri as 'y1' FROM w_levels_c WHERE obsid = 'PM-131' ORDER BY meas_cis Msg: syntax error at or near "'x'" LINE 1: SELECT meas_cis as 'x', meas_tri as 'y1' FROM w_levels_c WHE...

meas_cis and meas_tri are values (concentrations). The data set works with custom plot without any problems

HenrikSpa commented 3 years ago

What is your SQLite and Spatialite-version? Check QGIS meny Help > About. I can't replicate your error with SQLite version 3.29.0+Spatialite version 4.3.0 or SQLite 3.31.1+Spatialite version 4.3.0a.

mabi38 commented 3 years ago

I found this: PostgreSQL client version | 13.0 SpatiaLite version | 5.0.1

I using Midvatten with a PostGis database.

HenrikSpa commented 3 years ago

Ah, that explains why the SQL-query failed. I could replicate the error using PostGIS and have uploaded version 1.6.9 which fixes it.

mabi38 commented 3 years ago

Hello Hendrik Yes, now it is fixed. Thank you very much for the fast and fantastic support. Midvatten is now doing what I want to do.

Just a last question: If I select from a table for the x-axis 'time and date' (e.g., 2021-03-09 00:00) and for the y-axis 'meas' (numerical values) I receive this: Error: could not convert string to float: '2021-03-09 00:00'. So I guess the intention of the XY-plot is displaying just values vs. values. Is this correct?

Martin

HenrikSpa commented 3 years ago

Yes you're correct, XY-plot is only for values vs. values. Once upon a time it was used for presenting results from vlf and seismic measurements (distance as x-axis and ground surface, vlf and seismic measurements as y1, y2 and y3). The Section plot can be used for this now with the added value of stratigraphy bars.

Regards, Henrik