Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 05328c3

Browse filesBrowse files
authored
Merge pull request #634 from plotly/beef-up-animation-ex
CHANGELOG + animations docs
2 parents 325a2db + 3780607 commit 05328c3
Copy full SHA for 05328c3

File tree

Expand file treeCollapse file tree

2 files changed

+184
-14
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+184
-14
lines changed

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: CHANGELOG.md
+60-2Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2626
- Please note that these configuration options are for offline plots ONLY. For configuration options when embedding online plots please see our [embed tutorial](http://help.plot.ly/embed-graphs-in-websites/#step-8-customize-the-iframe).
2727
- `colors.py` file which contains functions for manipulating and validating colors and arrays of colors
2828
- 'scale' param in `FF.create_trisurf` which now can set the interpolation on the colorscales
29-
- animations now work in offline mode. By running `plotly.offline.plot()` and `plotly.offline.iplot()` with a `fig` with `frames`, the resulting plot will cycle through the figures defined in `frames` either in the browser or in an ipython notebook respectively. Here's an example
29+
- animations now work in offline mode. By running `plotly.offline.plot()` and `plotly.offline.iplot()` with a `fig` with `frames`, the resulting plot will cycle through the figures defined in `frames` either in the browser or in an ipython notebook respectively. Here's an example:
3030
```
3131
import IPython.display
3232
from IPython.display import display, HTML
@@ -46,7 +46,65 @@ figure_or_data = {'data': [{'x': [1, 2], 'y': [0, 1]}],
4646
iplot(figure_or_data)
4747
```
4848
More examples can be found at https://plot.ly/python/animations/.
49-
- Upcoming animations in online mode: use `plotly.plotly.create_animations` and `plotly.plotly.icreate_animations` which animate a figure with the `frames` argument.
49+
- animations now work in online mode: use `plotly.plotly.create_animations` and `plotly.plotly.icreate_animations` which animate a figure with the `frames` argument. Here is a simple example:
50+
```
51+
import plotly.plotly as py
52+
from plotly.grid_objs import Grid, Column
53+
54+
column_1 = Column([0.5], 'x')
55+
column_2 = Column([0.5], 'y')
56+
column_3 = Column([1.5], 'x2')
57+
column_4 = Column([1.5], 'y2')
58+
59+
grid = Grid([column_1, column_2, column_3, column_4])
60+
py.grid_ops.upload(grid, 'ping_pong_grid', auto_open=False)
61+
62+
# create figure
63+
figure = {
64+
'data': [
65+
{
66+
'xsrc': grid.get_column_reference('x'),
67+
'ysrc': grid.get_column_reference('y'),
68+
'mode': 'markers',
69+
}
70+
],
71+
'layout': {'title': 'Ping Pong Animation',
72+
'xaxis': {'range': [0, 2], 'autorange': False},
73+
'yaxis': {'range': [0, 2], 'autorange': False},
74+
'updatemenus': [{
75+
'buttons': [
76+
{'args': [None],
77+
'label': u'Play',
78+
'method': u'animate'}
79+
],
80+
'pad': {'r': 10, 't': 87},
81+
'showactive': False,
82+
'type': 'buttons'
83+
}]},
84+
'frames': [
85+
{
86+
'data': [
87+
{
88+
'xsrc': grid.get_column_reference('x2'),
89+
'ysrc': grid.get_column_reference('y2'),
90+
'mode': 'markers',
91+
}
92+
]
93+
},
94+
{
95+
'data': [
96+
{
97+
'xsrc': grid.get_column_reference('x'),
98+
'ysrc': grid.get_column_reference('y'),
99+
'mode': 'markers',
100+
}
101+
]
102+
}
103+
]
104+
}
105+
106+
py.create_animations(figure, 'ping_pong')
107+
```
50108

51109
### Fixed
52110
- Trisurf now uses correct `Plotly Colorscales` when called

‎plotly/plotly/plotly.py

Copy file name to clipboardExpand all lines: plotly/plotly/plotly.py
+124-12Lines changed: 124 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,36 +1517,148 @@ def create_animations(figure, filename=None, sharing='public', auto_open=True):
15171517
import plotly.plotly as py
15181518
from plotly.grid_objs import Grid, Column
15191519
1520-
column_1 = Column([1, 2, 3], 'x')
1521-
column_2 = Column([1, 3, 6], 'y')
1522-
column_3 = Column([2, 4, 6], 'new x')
1523-
column_4 = Column([1, 1, 5], 'new y')
1520+
column_1 = Column([0.5], 'x')
1521+
column_2 = Column([0.5], 'y')
1522+
column_3 = Column([1.5], 'x2')
1523+
column_4 = Column([1.5], 'y2')
1524+
15241525
grid = Grid([column_1, column_2, column_3, column_4])
1525-
py.grid_ops.upload(grid, 'animations_grid', auto_open=False)
1526+
py.grid_ops.upload(grid, 'ping_pong_grid', auto_open=False)
15261527
15271528
# create figure
15281529
figure = {
15291530
'data': [
15301531
{
15311532
'xsrc': grid.get_column_reference('x'),
1532-
'ysrc': grid.get_column_reference('y')
1533+
'ysrc': grid.get_column_reference('y'),
1534+
'mode': 'markers',
15331535
}
15341536
],
1535-
'layout': {'title': 'First Title'},
1537+
'layout': {'title': 'Ping Pong Animation',
1538+
'xaxis': {'range': [0, 2], 'autorange': False},
1539+
'yaxis': {'range': [0, 2], 'autorange': False},
1540+
'updatemenus': [{
1541+
'buttons': [
1542+
{'args': [None],
1543+
'label': u'Play',
1544+
'method': u'animate'}
1545+
],
1546+
'pad': {'r': 10, 't': 87},
1547+
'showactive': False,
1548+
'type': 'buttons'
1549+
}]},
15361550
'frames': [
15371551
{
15381552
'data': [
15391553
{
1540-
'xsrc': grid.get_column_reference('new x'),
1541-
'ysrc': grid.get_column_reference('new y')
1554+
'xsrc': grid.get_column_reference('x2'),
1555+
'ysrc': grid.get_column_reference('y2'),
1556+
'mode': 'markers',
1557+
}
1558+
]
1559+
},
1560+
{
1561+
'data': [
1562+
{
1563+
'xsrc': grid.get_column_reference('x'),
1564+
'ysrc': grid.get_column_reference('y'),
1565+
'mode': 'markers',
15421566
}
1543-
],
1544-
'layout': {'title': 'Second Title'}
1567+
]
15451568
}
15461569
]
15471570
}
15481571
1549-
py.create_animations(figure, 'new_plot_with_animations')
1572+
py.create_animations(figure, 'ping_pong')
1573+
```
1574+
1575+
Example 2: Growing Circles Animation
1576+
```
1577+
import plotly.plotly as py
1578+
from plotly.grid_objs import Grid, Column
1579+
1580+
column_1 = Column([0.9, 1.1], 'x')
1581+
column_2 = Column([1.0, 1.0], 'y')
1582+
column_3 = Column([0.8, 1.2], 'x2')
1583+
column_4 = Column([1.2, 0.8], 'y2')
1584+
column_5 = Column([0.7, 1.3], 'x3')
1585+
column_6 = Column([0.7, 1.3], 'y3')
1586+
column_7 = Column([0.6, 1.4], 'x4')
1587+
column_8 = Column([1.5, 0.5], 'y4')
1588+
column_9 = Column([0.4, 1.6], 'x5')
1589+
column_10 = Column([1.2, 0.8], 'y5')
1590+
1591+
grid = Grid([column_1, column_2, column_3, column_4, column_5,
1592+
column_6, column_7, column_8, column_9, column_10])
1593+
py.grid_ops.upload(grid, 'growing_circles_grid', auto_open=False)
1594+
1595+
# create figure
1596+
figure = {
1597+
'data': [
1598+
{
1599+
'xsrc': grid.get_column_reference('x'),
1600+
'ysrc': grid.get_column_reference('y'),
1601+
'mode': 'markers',
1602+
'marker': {'color': '#48186a', 'size': 10}
1603+
}
1604+
],
1605+
'layout': {'title': 'Growing Circles',
1606+
'xaxis': {'range': [0, 2], 'autorange': False},
1607+
'yaxis': {'range': [0, 2], 'autorange': False},
1608+
'updatemenus': [{
1609+
'buttons': [
1610+
{'args': [None],
1611+
'label': u'Play',
1612+
'method': u'animate'}
1613+
],
1614+
'pad': {'r': 10, 't': 87},
1615+
'showactive': False,
1616+
'type': 'buttons'
1617+
}]},
1618+
'frames': [
1619+
{
1620+
'data': [
1621+
{
1622+
'xsrc': grid.get_column_reference('x2'),
1623+
'ysrc': grid.get_column_reference('y2'),
1624+
'mode': 'markers',
1625+
'marker': {'color': '#3b528b', 'size': 25}
1626+
}
1627+
]
1628+
},
1629+
{
1630+
'data': [
1631+
{
1632+
'xsrc': grid.get_column_reference('x3'),
1633+
'ysrc': grid.get_column_reference('y3'),
1634+
'mode': 'markers',
1635+
'marker': {'color': '#26828e', 'size': 50}
1636+
}
1637+
]
1638+
},
1639+
{
1640+
'data': [
1641+
{
1642+
'xsrc': grid.get_column_reference('x4'),
1643+
'ysrc': grid.get_column_reference('y4'),
1644+
'mode': 'markers',
1645+
'marker': {'color': '#5ec962', 'size': 80}
1646+
}
1647+
]
1648+
},
1649+
{
1650+
'data': [
1651+
{
1652+
'xsrc': grid.get_column_reference('x5'),
1653+
'ysrc': grid.get_column_reference('y5'),
1654+
'mode': 'markers',
1655+
'marker': {'color': '#d8e219', 'size': 100}
1656+
}
1657+
]
1658+
}
1659+
]
1660+
}
1661+
py.create_animations(figure, 'growing_circles')
15501662
```
15511663
"""
15521664
credentials = get_credentials()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.