Comments (18)
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.
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.
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.
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.
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.
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.
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.
@hugadams , just wanted to make sure you saw this update for the changes we've been talking about.
from plotly.py.
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.
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.
from plotly.py.
@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.
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.
@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.
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.
Awesome! Can't wait to see the NB!
from plotly.py.
Cool, I'll try to get it updated by tomorrow.
from plotly.py.
Here is a draft of the tutorial:
and here is the main repo, and other tutorials:
https://github.com/hugadams/pyuvvis
from plotly.py.
Related Issues (20)
- Parallel coordinates mixed categrical and numerical values HOT 1
- Docs: "Download as HTML" recommends using a `data:` URL, which is restricted in Dash>=2.15.0 HOT 1
- multiple Legends not working in VS code HOT 2
- px.strip jitter doesn't work as expected due to underlying go.Box config HOT 1
- The color of Scattergl points are missing when using animation HOT 1
- tickmode='sync' option is not working as intended
- Cannot provide custom HTTP headers (e.g. bearer token) to Mapbox layer source HOT 2
- `Legendrank` does not work in plotly (pyscript) when `fill` argument is used HOT 2
- Test dependency versions are out of date
- why isn't fig.update_zaxes implimented
- Hover data not displaying on plotly map HOT 1
- plotly.express.scatter_geo() function cannot generate world map HOT 1
- Plotly legends cutoff in Quarto Dashboards
- Opacity and color not working together in px.scatter HOT 1
- Clarify installation of jupyterlab-plotly extension in documentation for JupyterLab 3.x HOT 2
- Making Radar Charts: make_trace_kwargs uses df.append which has been deprecated in pandas 2.0 HOT 1
- zorder doesn't work on version 5.21.0 HOT 5
- Shared X-axis spike remove tick marks from other subplots in Plotly?
- Update docs for using Jupyter HOT 1
- [Plotly Surface] Weird behavior of hover text for surfacecolor HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plotly.py.