import sys
!"{sys.executable}" -m pip install plotly
Collecting plotly Using cached https://files.pythonhosted.org/packages/f5/c3/03a183b94441da857e7d2b0564cb482bd15824dc1af2d2b337ea6e538c8f/plotly-4.5.4-py2.py3-none-any.whl Processing /Users/user/Library/Caches/pip/wheels/d7/a9/33/acc7b709e2a35caa7d4cae442f6fe6fbf2c43f80823d46460c/retrying-1.3.3-cp37-none-any.whl Requirement already satisfied: six in /Users/user/miniconda3/envs/py37-conv-topo/lib/python3.7/site-packages (from plotly) (1.12.0) Installing collected packages: retrying, plotly Successfully installed plotly-4.5.4 retrying-1.3.3
import sys
!"{sys.executable}" -m pip install --upgrade nbformat
Collecting nbformat Downloading https://files.pythonhosted.org/packages/ac/eb/de575b7a64e7ab8d8c95e4c180ccc36deda3f1379186c4ee7adf6c2f1586/nbformat-5.0.4-py3-none-any.whl (169kB) |████████████████████████████████| 174kB 1.2MB/s eta 0:00:01 Collecting jsonschema!=2.5.0,>=2.4 Downloading https://files.pythonhosted.org/packages/c5/8f/51e89ce52a085483359217bc72cdbf6e75ee595d5b1d4b5ade40c7e018b8/jsonschema-3.2.0-py2.py3-none-any.whl (56kB) |████████████████████████████████| 61kB 2.1MB/s eta 0:00:01 Requirement already satisfied, skipping upgrade: traitlets>=4.1 in /Users/user/miniconda3/envs/py37-conv-topo/lib/python3.7/site-packages (from nbformat) (4.3.3) Requirement already satisfied, skipping upgrade: jupyter-core in /Users/user/miniconda3/envs/py37-conv-topo/lib/python3.7/site-packages (from nbformat) (4.6.1) Requirement already satisfied, skipping upgrade: ipython-genutils in /Users/user/miniconda3/envs/py37-conv-topo/lib/python3.7/site-packages (from nbformat) (0.2.0) Collecting importlib-metadata; python_version < "3.8" Downloading https://files.pythonhosted.org/packages/8b/03/a00d504808808912751e64ccf414be53c29cad620e3de2421135fcae3025/importlib_metadata-1.5.0-py2.py3-none-any.whl Collecting attrs>=17.4.0 Downloading https://files.pythonhosted.org/packages/a2/db/4313ab3be961f7a763066401fb77f7748373b6094076ae2bda2806988af6/attrs-19.3.0-py2.py3-none-any.whl Collecting pyrsistent>=0.14.0 Downloading https://files.pythonhosted.org/packages/90/aa/cdcf7ef88cc0f831b6f14c8c57318824c9de9913fe8de38e46a98c069a35/pyrsistent-0.15.7.tar.gz (107kB) |████████████████████████████████| 112kB 25.6MB/s eta 0:00:01 Requirement already satisfied, skipping upgrade: six>=1.11.0 in /Users/user/miniconda3/envs/py37-conv-topo/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat) (1.12.0) Requirement already satisfied, skipping upgrade: setuptools in /Users/user/miniconda3/envs/py37-conv-topo/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat) (41.4.0) Requirement already satisfied, skipping upgrade: decorator in /Users/user/miniconda3/envs/py37-conv-topo/lib/python3.7/site-packages (from traitlets>=4.1->nbformat) (4.4.1) Collecting zipp>=0.5 Downloading https://files.pythonhosted.org/packages/b2/34/bfcb43cc0ba81f527bc4f40ef41ba2ff4080e047acb0586b56b3d017ace4/zipp-3.1.0-py3-none-any.whl Building wheels for collected packages: pyrsistent Building wheel for pyrsistent (setup.py) ... done Created wheel for pyrsistent: filename=pyrsistent-0.15.7-cp37-cp37m-macosx_10_9_x86_64.whl size=68792 sha256=1cf30c5c1b8242f712e8f54ed37e6e02f8a6b485dc95b9e000af70170ff8b483 Stored in directory: /Users/user/Library/Caches/pip/wheels/b5/78/ac/f26a78a989cd97f90981d96a560d7e1da5e1307284301d94e8 Successfully built pyrsistent Installing collected packages: zipp, importlib-metadata, attrs, pyrsistent, jsonschema, nbformat Successfully installed attrs-19.3.0 importlib-metadata-1.5.0 jsonschema-3.2.0 nbformat-5.0.4 pyrsistent-0.15.7 zipp-3.1.0
import plotly.graph_objects as go
import numpy as np
x = np.linspace(-3, 3, 100)
go.Figure([go.Scatter({'x': x, 'y': np.sin(1/x)}),
go.Scatter(x=[1, 2, 3], y=[0.5, 0.1, 0.3],
mode='markers')])
import numpy as np
x = np.linspace(-3, 3, 200)
y = np.linspace(-3, 3, 200)
X, Y = np.meshgrid(x, y) # магия!
go.Figure([go.Surface(x=X, y=Y, z=np.sin(X**2 + Y**2)), ], )
x = np.linspace(-3, 3, 5)
x
array([-3. , -1.5, 0. , 1.5, 3. ])
np.sin(x)
array([-0.14112001, -0.99749499, 0. , 0.99749499, 0.14112001])
x = np.linspace(-3, 3, 7)
y = np.linspace(-2, 2, 5)
x
array([-3., -2., -1., 0., 1., 2., 3.])
y
array([-2., -1., 0., 1., 2.])
X, Y = np.meshgrid(x, y)
X
array([[-3., -2., -1., 0., 1., 2., 3.], [-3., -2., -1., 0., 1., 2., 3.], [-3., -2., -1., 0., 1., 2., 3.], [-3., -2., -1., 0., 1., 2., 3.], [-3., -2., -1., 0., 1., 2., 3.]])
Y
array([[-2., -2., -2., -2., -2., -2., -2.], [-1., -1., -1., -1., -1., -1., -1.], [ 0., 0., 0., 0., 0., 0., 0.], [ 1., 1., 1., 1., 1., 1., 1.], [ 2., 2., 2., 2., 2., 2., 2.]])
X + Y
array([[-5., -4., -3., -2., -1., 0., 1.], [-4., -3., -2., -1., 0., 1., 2.], [-3., -2., -1., 0., 1., 2., 3.], [-2., -1., 0., 1., 2., 3., 4.], [-1., 0., 1., 2., 3., 4., 5.]])
import numpy as np
x, y, z = np.random.multivariate_normal(np.array([0, 0, 0]),
np.array([[3, 2, 0],
[2, 5, 1],
[0, 1, 4]]), size=200).T
go.Figure([go.Scatter3d(x=x, y=y, z=z ** 2, mode='markers')])