Repository: plotly/plotly.py

Issue:
subplots with legend in one of the plots does not work
This does not work, the problem is the legend

`````` python
from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go


fig = figure()
ax3 = subplot2grid((2,2),(0,1),rowspan=2)
ax1 = subplot2grid((2,2),(0,0))
ax2 = subplot2grid((2,2),(1,0))



ax1.plot([1,2],[5,2])
ax2.plot([1,2],[2,3])
ax3.plot([4,2],[7,3])
ax3.legend('dfsdf')## Without this line it does work
suptitle(Cell1)

plot_url = py.plot_mpl(fig)```
``````



Discussion:

Resolving patch:
diff --git a/plotly/matplotlylib/mplexporter/exporter.py b/plotly/matplotlylib/mplexporter/exporter.py
--- a/plotly/matplotlylib/mplexporter/exporter.py
+++ b/plotly/matplotlylib/mplexporter/exporter.py
@@ -162,8 +162,8 @@ def crawl_legend(self, ax, legend):
                 if isinstance(child, matplotlib.patches.Patch):
                     self.draw_patch(ax, child, force_trans=ax.transAxes)
                 elif isinstance(child, matplotlib.text.Text):
-                    if not (child is legend.get_children()[-1]
-                            and child.get_text() == 'None'):
+                    if (child is not legend.get_children()[-1]
+                            and child.get_text() != 'None'):
                         self.draw_text(ax, child, force_trans=ax.transAxes)
                 elif isinstance(child, matplotlib.lines.Line2D):
                     self.draw_line(ax, child, force_trans=ax.transAxes)
diff --git a/plotly/utils.py b/plotly/utils.py
--- a/plotly/utils.py
+++ b/plotly/utils.py
@@ -12,6 +12,7 @@
 import re
 import sys
 import threading
+import decimal
 
 import pytz
 
@@ -201,7 +202,8 @@ def default(self, obj):
             self.encode_as_pandas,
             self.encode_as_datetime,
             self.encode_as_date,
-            self.encode_as_list  # because some values have `tolist` do last.
+            self.encode_as_list,  # because some values have `tolist` do last.
+            self.encode_as_decimal
         )
         for encoding_method in encoding_methods:
             try:
@@ -296,6 +298,13 @@ def encode_as_date(obj):
         else:
             return iso_to_plotly_time_string(time_string)
 
+    @staticmethod
+    def encode_as_decimal(obj):
+        """Attempt to encode decimal by converting it to float"""
+        if isinstance(obj, decimal.Decimal):
+            return float(obj)
+        else:
+            raise NotEncodable
 
 ### unicode stuff ###
 def decode_unicode(coll):


Test patch:
diff --git a/plotly/tests/test_optional/test_utils/test_utils.py b/plotly/tests/test_optional/test_utils/test_utils.py
--- a/plotly/tests/test_optional/test_utils/test_utils.py
+++ b/plotly/tests/test_optional/test_utils/test_utils.py
@@ -7,6 +7,7 @@
 import datetime
 import json
 import math
+import decimal
 from datetime import datetime as dt
 from unittest import TestCase
 
@@ -149,6 +150,13 @@ def test_encode_as_date(self):
         )
         self.assertEqual(res, '2013-10-01 00:00:00.000010')
 
+    def test_encode_as_decimal(self):
+
+        # should work with decimal values
+        res = utils.PlotlyJSONEncoder.encode_as_decimal(decimal.Decimal(1.023452))
+
+        self.assertAlmostEqual(res, 1.023452) # Checks upto 7 decimal places
+        self.assertIsInstance(res, float)
 
 ## JSON encoding
 numeric_list = [1, 2, 3]