Code Monkey home page Code Monkey logo

Comments (18)

etpinard avatar etpinard commented on May 8, 2024

I am confirming the bug. matplotlib background colors are not successfully converted to Plotly.

Use the following code instead:

import matplotlib.pyplot as plt
fig = plt.figure()
# --> your matplotlib functions <--

import plotly.plotly as py  
import plotly.tools as tls

# Convert matplotlib figure to plotly figure object
fig_plotly = tls.mpl_to_plotly(fig)

# Add 'plot_bgcolor' to layout
fig_plotly['layout'].update(plot_bgcolor='rgb(128,0,0)')

# Send updated figure object to plotly
py.iplot(fig_plotly,filename='matplotlylib-bgcolor-test1')

from plotly.py.

theengineear avatar theengineear commented on May 8, 2024

Yes, you do have to manually add the plot_bgcolor attribute right now. There are a number of parameters that we currently don't support.

These get updated fairly often though, and when we feel confident that we have a new, large set of portable features from mpl, we'll likely shoot an email out to python users to discuss the new features.

Thanks for the feedback!

from plotly.py.

hughesadam87 avatar hughesadam87 commented on May 8, 2024

Thanks for the workaround. Perhaps down the road, this behavior could be incorporated into iplot_mpl() through a special keyword like overload as in:

iplot_mpl(fig, overload={'plot_bgcolor':'rgb(128,0,0)'}, **kwds)

Of course, the solution above is fine, but I can imagine this happening quite often as plotly catches on, and you'll have to re-explain this a lot.

Thanks for the help.

from plotly.py.

hughesadam87 avatar hughesadam87 commented on May 8, 2024

Any qualms if I put that aforementioned overload keyword into a wrapper in one of my libraries for the time being, and incorporate it into a tutorial I'm writing?

from plotly.py.

theengineear avatar theengineear commented on May 8, 2024

If it will make the tutorial easier to work though, by all means, go for it!

I'm not sure that something quite like this would be adopted because of the ambiguity of the keywords in overload. There are many repeating keywords in plotly's figure objects since the organization is encapsulated in sub-dictionaries. Therefore, I'd be more in favor of a solution that looked like this:

figure_update = {'layout': {'plot_bgcolor':'rgb(128,0,0)'}}
iplot_mpl(fig, update=figure_update, **kwds)

In the background, then, it's clear that we're just going to update the resulting figure with the figure_update dictionary (with protection from nesting stuff).

We're trying to not do too much magic in the background after user calls. I'm certainly open to any solution here that doesn't introduce any ambiguity.

If this solution seems like it would work for you, I' be happy to write it in (even before your tutorial) if you give me a timeframe on it.

from plotly.py.

hughesadam87 avatar hughesadam87 commented on May 8, 2024

Hi,

Yes, I think that solution is better. We aren't really hard pressed for time, but if it does get written in, we'll certainly start using it asap. I'll keep an eye on this thread. If it does get changed, can you drop me a line either here or @hughesadam87 on twitter?

Thanks

from plotly.py.

theengineear avatar theengineear commented on May 8, 2024

Ok, I pushed a branch called 'mpl-updated' that should fix this. Here's an NB showing how it'll work:
http://nbviewer.ipython.org/gist/theengineear/0719fd0ac63c9b4ceba3

If you like this, let me know and i'll merge it and update our PyPI.

from plotly.py.

theengineear avatar theengineear commented on May 8, 2024

@hugadams , just wanted to make sure you saw this update for the changes we've been talking about.

from plotly.py.

hughesadam87 avatar hughesadam87 commented on May 8, 2024

@theengineear

Thanks. I'm going to try it now; looks exactly what I had hoped for. Will be back in 30 min or so and will share our updated plotly tutorial. BTB

from plotly.py.

hughesadam87 avatar hughesadam87 commented on May 8, 2024

So, I think you are fine to update PyPI based on the notebook you shared, but after installing this, I cannot import plotly. I've completely removed plotly from my sitepackages prior to installing; however, I'm using Enthought canopy and it could be that there's some other vestige of the old version somewhere. Here's the error I get, not sure if its reproducible:

        ---------------------------------------------------------------------------
        ImportError                               Traceback (most recent call last)
        <ipython-input-3-bd46b6da962d> in <module>()
        ----> 1 import plotly.plotly as py
              2 #import plotly.tools as tls
              3 
              4 #tls.get_credentials()
              5 #py.sign_in('user', 'pw')

        /home/glue/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/plotly-1.0.26-py2.7.egg/plotly/__init__.py in <module>()
              1 from . version import __version__
        ----> 2 import graph_objs
              3 import plotly
              4 import tools
              5 import utils

        /home/glue/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/plotly-1.0.26-py2.7.egg/plotly/graph_objs/__init__.py in <module>()
             44 
             45 """
        ---> 46 from graph_objs import *
             47 
             48 __all__ = ["Data",

        /home/glue/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/plotly-1.0.26-py2.7.egg/plotly/graph_objs/graph_objs.py in <module>()
             27 import json
             28 import textwrap
        ---> 29 from .. import exceptions
             30 from .. import utils
             31 

        ImportError: cannot import name exceptions

from plotly.py.

theengineear avatar theengineear commented on May 8, 2024

screen shot 2014-06-14 at 6 43 01 pm

from plotly.py.

theengineear avatar theengineear commented on May 8, 2024

@hugadams , i can't seem to reproduce it, but i'm going to go ahead an change our module name, excpetions looks to be causing a name clash.

from plotly.py.

hughesadam87 avatar hughesadam87 commented on May 8, 2024

Hmm, it's probably on my end. Still getting an import error, not on my other computer. I went ahead and deleted my old version of plotly from site packages. I'm sure it's something on my end, so I'd recommend pushing to PyPI if you are happy with the changes. I'll get it straightened out on my builds. FYI, here is what it's saying now (again, on a separate computer)

import plotly
Traceback (most recent call last):
File "", line 1, in
File "plotly/init.py", line 2, in
import graph_objs
File "plotly/graph_objs/init.py", line 46, in
from graph_objs import *
File "plotly/graph_objs/graph_objs.py", line 69, in
'graph_reference/graph_objs_meta.json').decode('utf-8')
File "/home/adam/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/pkg_resources.py", line 928, in resource_string
self, resource_name
File "/home/adam/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/pkg_resources.py", line 1226, in get_resource_string
return self._get(self._fn(self.module_path, resource_name))
File "/home/adam/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/pkg_resources.py", line 1353, in _get
stream = open(path, 'rb')
IOError: [Errno 2] No such file or directory: 'plotly/graph_reference/graph_objs_meta.json'

from plotly.py.

theengineear avatar theengineear commented on May 8, 2024

@hugadams , plotly 1.0.27 on PyPI now has the update kwarg as discussed. I'm not going to make a change to exceptions until we can get a replicable bug. Unfortunately, renaming this module may destroy try-except blocks since the modules will no longer exist.

I'm going to close this issue, but if you still get this error on the next upgrade to 1.0.27, would you open up a new issue thread related to the cannot import name error you were getting?

If if is something on our end, we'll want to address it, but I'm just having a hard time making that error pop up.

from plotly.py.

hughesadam87 avatar hughesadam87 commented on May 8, 2024

Thanks. Actually, installing form pip now that's it updated did fix my problem. Who knows, but glad it's fixed. Thanks for implementing this!

from plotly.py.

theengineear avatar theengineear commented on May 8, 2024

Awesome! Can't wait to see the NB!

from plotly.py.

hughesadam87 avatar hughesadam87 commented on May 8, 2024

Cool, I'll try to get it updated by tomorrow.

from plotly.py.

hughesadam87 avatar hughesadam87 commented on May 8, 2024

Here is a draft of the tutorial:

http://nbviewer.ipython.org/github/hugadams/pyuvvis/blob/master/examples/Notebooks/plotly.ipynb?create=1

and here is the main repo, and other tutorials:

https://github.com/hugadams/pyuvvis

from plotly.py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.