214 lines
4.7 KiB
Plaintext
214 lines
4.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"outputs": [],
|
|
"source": [
|
|
"import space.kscience.plotly.server.PlotlyServerIntegration\n",
|
|
"import space.kscience.plotly.server.jupyter\n",
|
|
"\n",
|
|
"USE(PlotlyServerIntegration())"
|
|
],
|
|
"metadata": {
|
|
"collapsed": false
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import kotlin.math.*"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"val x1 = (0..100).map { it.toDouble() / 100.0 }\n",
|
|
"val y1 = x1.map { sin(2.0 * PI * it) }\n",
|
|
"val y2 = x1.map { cos(2.0 * PI * it) }\n",
|
|
"\n",
|
|
"val trace1 = Trace(x1, y1) { name = \"sin\" }\n",
|
|
"val trace2 = Trace(x1, y2) { name = \"cos\" }\n",
|
|
"\n",
|
|
"val fragment = Plotly.fragment { renderer ->\n",
|
|
" val plotConfig = PlotlyConfig {\n",
|
|
" responsive = true\n",
|
|
" }\n",
|
|
"\n",
|
|
" plot(\"above\", config = plotConfig, renderer = renderer) {\n",
|
|
" traces(trace1, trace2)\n",
|
|
" layout {\n",
|
|
" title = \"The plot above\"\n",
|
|
" xaxis.title = \"x axis name\"\n",
|
|
" yaxis.title = \"y axis name\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" hr()\n",
|
|
" h1 { +\"A custom separator\" }\n",
|
|
" hr()\n",
|
|
" div {\n",
|
|
" plot(\"below\", renderer = renderer) {\n",
|
|
" traces(trace1, trace2)\n",
|
|
" layout {\n",
|
|
" title = \"The plot below\"\n",
|
|
" xaxis.title = \"x axis name\"\n",
|
|
" yaxis.title = \"y axis name\"\n",
|
|
" }\n",
|
|
" }\n",
|
|
" }\n",
|
|
"}\n",
|
|
"fragment"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"Plotly.plot {\n",
|
|
" traces(trace1, trace2)\n",
|
|
" layout {\n",
|
|
" title = \"The plot below\"\n",
|
|
" xaxis.title = \"x axis name\"\n",
|
|
" yaxis.title = \"y axis name\"\n",
|
|
" }\n",
|
|
"}"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"val x = (0..100).map { it.toDouble() / 100.0 }\n",
|
|
"val y = x.map { sin(2.0 * PI * it) }\n",
|
|
"\n",
|
|
"val trace = Trace(x, y) { name = \"sin\" }\n",
|
|
"\n",
|
|
"\n",
|
|
"val dynamicPlot = Plotly.plot {\n",
|
|
" traces(trace)\n",
|
|
" layout {\n",
|
|
" title = \"Dynamic plot\"\n",
|
|
" xaxis.title = \"x axis name\"\n",
|
|
" yaxis.title = \"y axis name\"\n",
|
|
" }\n",
|
|
"}\n",
|
|
"\n",
|
|
"dynamicPlot"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import kotlinx.coroutines.*\n",
|
|
"\n",
|
|
"val job = GlobalScope.launch {\n",
|
|
" var time: Long = 0\n",
|
|
" while (isActive) {\n",
|
|
" delay(10)\n",
|
|
" time += 10\n",
|
|
" val dynamicY = x.map { sin(2.0 * PI * (it + time.toDouble() / 1000.0)) }\n",
|
|
" trace.y.set(dynamicY)\n",
|
|
" }\n",
|
|
"}"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"job.cancel()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"dynamicPlot.layout.xaxis.title = \"крокозябра\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"Plotly.jupyter.port = 8884"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"Plotly.jupyter.port"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"outputs": [],
|
|
"source": [],
|
|
"metadata": {
|
|
"collapsed": false
|
|
}
|
|
}
|
|
],
|
|
"metadata": {
|
|
"@webio": {
|
|
"lastCommId": null,
|
|
"lastKernelId": null
|
|
},
|
|
"hide_input": false,
|
|
"kernelspec": {
|
|
"display_name": "Kotlin",
|
|
"language": "kotlin",
|
|
"name": "kotlin"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": "text/x-kotlin",
|
|
"file_extension": ".kt",
|
|
"mimetype": "text/x-kotlin",
|
|
"name": "kotlin",
|
|
"nbconvert_exporter": "",
|
|
"pygments_lexer": "kotlin",
|
|
"version": "1.5.30-dev-598"
|
|
},
|
|
"toc": {
|
|
"base_numbering": 1,
|
|
"nav_menu": {},
|
|
"number_sections": false,
|
|
"sideBar": false,
|
|
"skip_h1_title": false,
|
|
"title_cell": "Table of Contents",
|
|
"title_sidebar": "Contents",
|
|
"toc_cell": false,
|
|
"toc_position": {},
|
|
"toc_section_display": false,
|
|
"toc_window_display": false
|
|
},
|
|
"ktnbPluginMetadata": {
|
|
"projectDependencies": true
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|