Note
Click here to download the full example code
12. Matplotlib to Plotly
[REF] https://github.com/plotly/plotly.py/issues/3624#issuecomment-1161805210
Note
In the latest commit of plotly packages/python/plotly/plotly/matplotlylib/mpltools.py line 368, it still calls is_frame_like() function. There is already an issue tracking this. You may need choose to downgrade Matplotlib if you still want to use mpl_to_plotly() function.
Out:
'\n# Convert to plotly\nimport plotly.tools as tls\n\n# Convert to plotly\nfig = tls.mpl_to_plotly(fig)\n\nprint(fig.data)\n\n# Show\n#fig.show()\nfig\n'
13 # Libraries
14 import numpy as np
15 import matplotlib.pyplot as plt
16
17 try:
18 __file__
19 TERMINAL = True
20 except:
21 TERMINAL = False
22
23
24 # Create data
25 x = np.arange(10)
26 y = 2.5 * np.sin(x / 20 * np.pi)
27 yerr = np.linspace(0.05, 0.2, 10)
28
29 # Figure
30 fig = plt.figure()
31 plt.errorbar(x, y + 3, yerr=yerr, label='both limits (default)')
32 plt.errorbar(x, y + 2, yerr=yerr, uplims=True, label='uplims=True')
33 plt.errorbar(x, y + 1, yerr=yerr, uplims=True, lolims=True,
34 label='uplims=True, lolims=True')
35
36 # Add error
37 upperlimits = [True, False] * 5
38 lowerlimits = [False, True] * 5
39 plt.errorbar(x, y, yerr=yerr, uplims=upperlimits, lolims=lowerlimits,
40 label='subsets of uplims and lolims')
41
42 # add legent
43 plt.legend(loc='lower right')
44
45 """
46 # Convert to plotly
47 import plotly.tools as tls
48
49 # Convert to plotly
50 fig = tls.mpl_to_plotly(fig)
51
52 print(fig.data)
53
54 # Show
55 #fig.show()
56 fig
57 """
Total running time of the script: ( 0 minutes 0.112 seconds)