Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matplotlib Figure object not supporting 'validate' and 'strip_style' #1128

Closed
priyatharsan opened this issue Aug 22, 2018 · 1 comment
Closed
Milestone

Comments

@priyatharsan
Copy link
Contributor

priyatharsan commented Aug 22, 2018

Matplotlib Figure object is not supporting validate method

fig.validate()

Sample Code:

fig, ax = plt.subplots()
ax.plot(y0, label='y0')
ax.plot(y1, label='y1')
ax.plot(y2, label='y2')
ax.plot(capacity, label='capacity')

# set all traces' "fill" so that it fills to the next 'y' trace
update = {'data':[{'fill': 'tonexty'}]}

# strip style just lets Plotly make the styling choices (e.g., colors)
plot_url = py.iplot_mpl(fig, update=update, filename='mpl-stacked-line')

Error:

site-packages\plotly\plotly\plotly.pyc in iplot_mpl(fig, resize, strip_style, update, **plot_options)
    280     if update and isinstance(update, dict):
    281         fig.update(update)
--> 282         fig.validate()
    283     elif update is not None:
    284         raise exceptions.PlotlyGraphObjectError(

AttributeError: 'Figure' object has no attribute 'validate'

And for strip_style

def iplot_mpl(fig, resize=True, strip_style=False, update=None,

Sample Code:

plot_url = py.iplot_mpl(fig, update=update, strip_style=True, filename='mpl-stacked-line')

Error:

C:\Anaconda\Anaconda2\lib\site-packages\plotly\plotly\plotly.pyc in iplot_mpl(fig, resize, strip_style, update, **plot_options)
    277 
    278     """
--> 279     fig = tools.mpl_to_plotly(fig, resize=resize, strip_style=strip_style)
    280     if update and isinstance(update, dict):
    281         fig.update(update)

C:\Anaconda\Anaconda2\lib\site-packages\plotly\tools.pyc in mpl_to_plotly(fig, resize, strip_style, verbose)
    467             renderer.resize()
    468         if strip_style:
--> 469             renderer.strip_style()
    470         if verbose:
    471             print(renderer.msg)

C:\Anaconda\Anaconda2\lib\site-packages\plotly\matplotlylib\renderer.pyc in strip_style(self)
    737     def strip_style(self):
    738         self.msg += "Stripping mpl style, deleting keys from data and layout\n"
--> 739         self.plotly_fig.strip_style()

AttributeError: 'Figure' object has no attribute 'strip_style'
@arailly
Copy link

arailly commented Nov 30, 2018

Hasn't the problem solved yet?
I have same problem.

code(it is the tutorial of "mne" module, ref→ https://plot.ly/ipython-notebooks/mne-tutorial/ )

picks = mne.pick_types(raw.info, meg='mag', exclude=[])
data, times = raw[picks[:10], start:stop]

import matplotlib.pyplot as plt
import plotly.plotly as py

plt.plot(times, data.T)
plt.xlabel('time (s)')
plt.ylabel('MEG data (T)')

update = dict(layout=dict(showlegend=True), data=[dict(name=raw.info['ch_names'][p]) for p in picks[:10]])
py.iplot_mpl(plt.gcf(), update=update)

error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-bb858f00c877> in <module>()
     10 
     11 update = dict(layout=dict(showlegend=True), data=[dict(name=raw.info['ch_names'][p]) for p in picks[:10]])
---> 12 py.iplot_mpl(plt.gcf(), update=update)

/usr/local/lib/python3.7/site-packages/plotly/plotly/plotly.py in iplot_mpl(fig, resize, strip_style, update, **plot_options)
    277     if update and isinstance(update, dict):
    278         fig.update(update)
--> 279         fig.validate()
    280     elif update is not None:
    281         raise exceptions.PlotlyGraphObjectError(

AttributeError: 'Figure' object has no attribute 'validate'

environment:

Mac OS 10.14.1
Python 3.7.0
mne 0.17.0 (install with pip3)
plotly 3.4.2 (install with pip3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants