Þ ¥bonds€¬cell_resultsÞ Ù$048f54ba-45d1-49e2-b19d-7ef634c77cf0Цqueued¤logs�§running¦output†¤bodyÛ ¯
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†E”°persist_js_state·has_pluto_hook_features§cell_idÙ$048f54ba-45d1-49e2-b19d-7ef634c77cf0¹depends_on_disabled_cells§runtimeÏ ý�6µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$b1658a17-b59f-4c35-b7a0-1503e377c731Цqueued¤logs�§running¦output†¤bodyÙÁThe following cell automatically updates the content of the observable val_obs each time we move the slider. In turn, it updates the plot below.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7æØŒ°persist_js_state·has_pluto_hook_features§cell_idÙ$b1658a17-b59f-4c35-b7a0-1503e377c731¹depends_on_disabled_cells§runtimeÎ ˆ;µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$774f1c41-7a84-401a-950c-466cf05fcd92Цqueued¤logs�§running¦output†¤bodyÚXWarning
The code must be separated into four cells as above (slider, definition of the observable, update of the observable, plot). In fact, the definition of the observable could be included in the "plot cell".
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7æûô°persist_js_state·has_pluto_hook_features§cell_idÙ$774f1c41-7a84-401a-950c-466cf05fcd92¹depends_on_disabled_cells§runtimeÎ Ú„µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$a6937e90-5714-4023-aaf5-02909c53daa7Цqueued¤logs�§running¦output†¤bodyÛ +¨¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†G‚Z°persist_js_state·has_pluto_hook_features§cell_idÙ$a6937e90-5714-4023-aaf5-02909c53daa7¹depends_on_disabled_cells§runtimeÎ#E¶Åµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$b496ac83-b3c7-4758-994e-7534abc56932Цqueued¤logs�§running¦output†¤body¬0.0:0.01:0.0¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ†GHÛ<°persist_js_state·has_pluto_hook_features§cell_idÙ$b496ac83-b3c7-4758-994e-7534abc56932¹depends_on_disabled_cells§runtimeÍ9€µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$df840868-75d4-4687-8556-19eeab1e4115Цqueued¤logs�§running¦output†¤bodyÙ‚
Integration in Pluto (with PlutoUI)
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7æ|þ°persist_js_state·has_pluto_hook_features§cell_idÙ$df840868-75d4-4687-8556-19eeab1e4115¹depends_on_disabled_cells§runtimeÎ ¥Yµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$d353c065-7802-4f18-8492-008b860b9379Цqueued¤logs�§running¦output†¤bodyÙ6
Makie
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7å °persist_js_state·has_pluto_hook_features§cell_idÙ$d353c065-7802-4f18-8492-008b860b9379¹depends_on_disabled_cells§runtimeÎ œrµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$5b5f4616-0f66-455a-8e90-4f4027befc51Цqueued¤logs�§running¦output†¤bodyÙ~
Interactivity and animations via WGLMakie
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7å{°persist_js_state·has_pluto_hook_features§cell_idÙ$5b5f4616-0f66-455a-8e90-4f4027befc51¹depends_on_disabled_cells§runtimeÎ ¾2µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$13c42895-ad10-4f99-adc2-a3f371987d56Цqueued¤logs�§running¦output†¤bodyÚþWe recommend to put all the commands related to the Makie animation (usually starting with fig = Figure(...) and ending with fig) in a let ... end block. Hence all variables defined in the block are defined locally. In particular they are not reactive and the same variable name (e.g. fig, ax, etc.) can be used in several let ... end blocks.
Warning
Since some interactive components (e.g. Slider) are also exported by other packages (e.g. PlutoUI), you may need to write Makie.Slider to avoid ambiguity.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7æ@W°persist_js_state·has_pluto_hook_features§cell_idÙ$13c42895-ad10-4f99-adc2-a3f371987d56¹depends_on_disabled_cells§runtimeÎ è…µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$6d79f301-b6b4-40be-b48e-e194466b5170Цqueued¤logs�§running¦output†¤bodyÚNote
The plot above is internaly updated thanks to the Observable type. It is not replotted each time val is modified. Compare with:
let
val_non_obs = 0:0.01:val
x = @. exp(- val_non_obs/8) * cos(val_non_obs)
y = @. exp(- val_non_obs/8) * sin(val_non_obs)
lines(x,y, axis=(;limits=(-1,2,-1,1)))
end
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7ç‚°persist_js_state·has_pluto_hook_features§cell_idÙ$6d79f301-b6b4-40be-b48e-e194466b5170¹depends_on_disabled_cells§runtimeÎ å#µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$d6c97e29-74b6-4be3-bf2a-0aba966e1eadЦqueued¤logs�§running¦output†¤bodyÚWarning
This notedbook cannot be viewed statically online (as a featured notebook), you need to Run this notebook to see the plots.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7å7Ú°persist_js_state·has_pluto_hook_features§cell_idÙ$d6c97e29-74b6-4be3-bf2a-0aba966e1ead¹depends_on_disabled_cells§runtimeÎ x<µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$2220f4b9-02bd-4540-a32e-124b90cd3033Цqueued¤logs�§running¦output†¤bodyÙ”Makie animations can be integrated almost seamlessly into Pluto notebooks via the WGLMakie backend.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7æ"°persist_js_state·has_pluto_hook_features§cell_idÙ$2220f4b9-02bd-4540-a32e-124b90cd3033¹depends_on_disabled_cells§runtimeÎ ý˵published_object_keys�¸depends_on_skipped_cells§erroredÂÙ$96269a69-e678-4a9f-87c2-6215032b42d1Цqueued¤logs�§running¦output†¤body¸Observable(0.0:0.1:0.0)
¤mimeªtext/plain¬rootassignee§val_obs²last_run_timestampËAÚ†G4C¦°persist_js_state·has_pluto_hook_features§cell_idÙ$96269a69-e678-4a9f-87c2-6215032b42d1¹depends_on_disabled_cells§runtimeÍ>еpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$2ed1866c-1d9a-4992-a98d-4492ebe8ca44Цqueued¤logs�§running¦output†¤bodyÚ:Here is an example of interactive plot. You can push the Live Update button to get a moving curve. It is taken from Makie documentation on toggles . You may have to manually run the cell below.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7å�‚°persist_js_state·has_pluto_hook_features§cell_idÙ$2ed1866c-1d9a-4992-a98d-4492ebe8ca44¹depends_on_disabled_cells§runtimeÎ Tµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9d306b48-df32-11f0-b15f-7540889fd2b7Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ†=ì=°persist_js_state·has_pluto_hook_features§cell_idÙ$9d306b48-df32-11f0-b15f-7540889fd2b7¹depends_on_disabled_cells§runtimeÏ s·Hµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$b8b581e9-5085-4763-8f46-2aa718925635Цqueued¤logs�§running¦output†¤bodyÙa ¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†FûKñ°persist_js_state·has_pluto_hook_features§cell_idÙ$b8b581e9-5085-4763-8f46-2aa718925635¹depends_on_disabled_cells§runtimeÎh,âµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9e86e965-7a3e-43bc-930a-5d916273770fЦqueued¤logs�§running¦output†¤bodyÚ.There is an intermediate solution that combines Makie's Observable with PlutoUI's interactivity. Here is a simple example with a PlutoUI.Slider where we want to plot some values generated from a range between 0 and val.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7æš,°persist_js_state·has_pluto_hook_features§cell_idÙ$9e86e965-7a3e-43bc-930a-5d916273770f¹depends_on_disabled_cells§runtimeÎ zóµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$91a90dc6-4f33-403d-b7f2-837fed4a0304Цqueued¤logs�§running¦output†¤bodyÙ½¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7æ`‰°persist_js_state·has_pluto_hook_features§cell_idÙ$91a90dc6-4f33-403d-b7f2-837fed4a0304¹depends_on_disabled_cells§runtimeÎ Ê+µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9cf1da97-dcb0-4691-8597-44bc62dff257Цqueued¤logs�§running¦output†¤bodyÙˆ
Integration in Pluto (without PlutoUI)
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7åóÔ°persist_js_state·has_pluto_hook_features§cell_idÙ$9cf1da97-dcb0-4691-8597-44bc62dff257¹depends_on_disabled_cells§runtimeÎ “±µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$86f8bb60-7e4c-4acd-af9c-ada0c589f7a5Цqueued¤logs�§running¦output†¤bodyÚŸThen, we initialize an Observable. The argument 0.0:0.1:0.0 is only used for initialization. It only has to respect the type that we want, i.e. StepRange here. In case you don't know the type in advance, you could force it to be Any via val_obs = Observable{Any}(0) for instance.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7æ»b°persist_js_state·has_pluto_hook_features§cell_idÙ$86f8bb60-7e4c-4acd-af9c-ada0c589f7a5¹depends_on_disabled_cells§runtimeÎ Óµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$4acece79-c67c-420e-a688-679d4c4dbe36Цqueued¤logs�§running¦output†¤bodyÚøThe most natural way to put interactivity within a Pluto notebook is to use the @bind macro from PlutoUI.jl coupled with Pluto reactivity. The PlutoUI notebook gives lots of examples to elaborate on.
The objective of the present notebook is to present an alternative using the Makie ecosystem.
Warning
The Makie package is a powerful plotting package, but it takes a while to install and precompile. Therefore, this notebook will be a bit slow to start the first time you run it.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7åi¥°persist_js_state·has_pluto_hook_features§cell_idÙ$4acece79-c67c-420e-a688-679d4c4dbe36¹depends_on_disabled_cells§runtimeÎ J®µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$78ccde0f-fdca-4db3-9af3-caa3a0963b23Цqueued¤logs�§running¦output†¤body ¤mimeªtext/plain¬rootassigneeÀ²last_run_timestampËAÚ†>Ñø°persist_js_state·has_pluto_hook_features§cell_idÙ$78ccde0f-fdca-4db3-9af3-caa3a0963b23¹depends_on_disabled_cells§runtimeΤÄJµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$6a54d18f-45ec-4917-843e-d6af2660525cЦqueued¤logs�§running¦output†¤bodyÚ`There are two main drawbacks when using pure Makie animations:
it relies on the heavy Makie ecosystem (long to precompile and run),
it is harder to get global dependencies in your animations than if you are using PlutoUI and reactivity.
Hence, if you plan to share your notebook you should avoid to use Makie.
However, if you plan to produce slides for a presentation, using Makie is a great option. It gives high quality plots and highly customizable animations that will make your slides shine.
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7çpΰpersist_js_state·has_pluto_hook_features§cell_idÙ$6a54d18f-45ec-4917-843e-d6af2660525c¹depends_on_disabled_cells§runtimeÎ ‰—µpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$917f2df5-f63f-4937-b1e0-b60ed4351d9fЦqueued¤logs�§running¦output†¤bodyÙ@
Conclusion
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7ç:›°persist_js_state·has_pluto_hook_features§cell_idÙ$917f2df5-f63f-4937-b1e0-b60ed4351d9f¹depends_on_disabled_cells§runtimeÎ ™ñµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$9d9b338e-c859-4089-aa27-40742dbfd054Цqueued¤logs�§running¦output†¤bodyÛ +¤¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†F¾ ‘°persist_js_state·has_pluto_hook_features§cell_idÙ$9d9b338e-c859-4089-aa27-40742dbfd054¹depends_on_disabled_cells§runtimeÏ DéHPµpublished_object_keys�¸depends_on_skipped_cells§erroredÂÙ$106e4592-7ddc-4388-b92d-d41933828032Цqueued¤logs�§running¦output†¤bodyÚ#If you are not familiar with Makie, here is Makie's basic tutorial dealing with static single plots and Makie's advanced tutorial dealing with layouts of multiple plots.
If you are familiar with Makie for static plots, but not for animations, have a look at Makie's animation tutorial .
¤mime©text/html¬rootassigneeÀ²last_run_timestampËAÚ†7å×°persist_js_state·has_pluto_hook_features§cell_idÙ$106e4592-7ddc-4388-b92d-d41933828032¹depends_on_disabled_cells§runtimeÎ m}µpublished_object_keys�¸depends_on_skipped_cells§errored±cell_dependenciesÞ Ù$048f54ba-45d1-49e2-b19d-7ef634c77cf0„´precedence_heuristic §cell_idÙ$048f54ba-45d1-49e2-b19d-7ef634c77cf0´downstream_cells_map€²upstream_cells_mapÞ £sin�¡:�±hidexdecorations!�¥Label�¤lift�¨@__dot__�ªGridLayout�¦lines!�¡-�¥range�¡^�¢on�¡+�¦Toggle�¡*�ªObservable�¦Figure�¤Axis�Ù$b1658a17-b59f-4c35-b7a0-1503e377c731„´precedence_heuristic §cell_idÙ$b1658a17-b59f-4c35-b7a0-1503e377c731´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$774f1c41-7a84-401a-950c-466cf05fcd92„´precedence_heuristic §cell_idÙ$774f1c41-7a84-401a-950c-466cf05fcd92´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$a6937e90-5714-4023-aaf5-02909c53daa7„´precedence_heuristic §cell_idÙ$a6937e90-5714-4023-aaf5-02909c53daa7´downstream_cells_map‚¡x�¡y�²upstream_cells_mapŒ£exp�¥Makie�¥@lift�¥lines�¨@__dot__�ªMakie.lift�¡-�§val_obs‘Ù$96269a69-e678-4a9f-87c2-6215032b42d1¡/�¡*�£cos�£sin�Ù$b496ac83-b3c7-4758-994e-7534abc56932„´precedence_heuristic §cell_idÙ$b496ac83-b3c7-4758-994e-7534abc56932´downstream_cells_map€²upstream_cells_mapƒ¡:�§val_obs‘Ù$96269a69-e678-4a9f-87c2-6215032b42d1£val‘Ù$b8b581e9-5085-4763-8f46-2aa718925635Ù$df840868-75d4-4687-8556-19eeab1e4115„´precedence_heuristic §cell_idÙ$df840868-75d4-4687-8556-19eeab1e4115´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$d353c065-7802-4f18-8492-008b860b9379„´precedence_heuristic §cell_idÙ$d353c065-7802-4f18-8492-008b860b9379´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$5b5f4616-0f66-455a-8e90-4f4027befc51„´precedence_heuristic §cell_idÙ$5b5f4616-0f66-455a-8e90-4f4027befc51´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$13c42895-ad10-4f99-adc2-a3f371987d56„´precedence_heuristic §cell_idÙ$13c42895-ad10-4f99-adc2-a3f371987d56´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$6d79f301-b6b4-40be-b48e-e194466b5170„´precedence_heuristic §cell_idÙ$6d79f301-b6b4-40be-b48e-e194466b5170´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$d6c97e29-74b6-4be3-bf2a-0aba966e1ead„´precedence_heuristic §cell_idÙ$d6c97e29-74b6-4be3-bf2a-0aba966e1ead´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$2220f4b9-02bd-4540-a32e-124b90cd3033„´precedence_heuristic §cell_idÙ$2220f4b9-02bd-4540-a32e-124b90cd3033´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$96269a69-e678-4a9f-87c2-6215032b42d1„´precedence_heuristic §cell_idÙ$96269a69-e678-4a9f-87c2-6215032b42d1´downstream_cells_map�§val_obs’Ù$b496ac83-b3c7-4758-994e-7534abc56932Ù$a6937e90-5714-4023-aaf5-02909c53daa7²upstream_cells_map‚¡:�ªObservable�Ù$2ed1866c-1d9a-4992-a98d-4492ebe8ca44„´precedence_heuristic §cell_idÙ$2ed1866c-1d9a-4992-a98d-4492ebe8ca44´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$9d306b48-df32-11f0-b15f-7540889fd2b7„´precedence_heuristic§cell_idÙ$9d306b48-df32-11f0-b15f-7540889fd2b7´downstream_cells_map�¨WGLMakie�²upstream_cells_map€Ù$b8b581e9-5085-4763-8f46-2aa718925635„´precedence_heuristic §cell_idÙ$b8b581e9-5085-4763-8f46-2aa718925635´downstream_cells_map�£val‘Ù$b496ac83-b3c7-4758-994e-7534abc56932²upstream_cells_mapФCore�¤Base�¡:�·PlutoRunner.create_bond�«PlutoRunner�§PlutoUI‘Ù$78ccde0f-fdca-4db3-9af3-caa3a0963b23¯Core.applicable�¥@bind�¨Base.get�®PlutoUI.Slider�Ù$9e86e965-7a3e-43bc-930a-5d916273770f„´precedence_heuristic §cell_idÙ$9e86e965-7a3e-43bc-930a-5d916273770f´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$91a90dc6-4f33-403d-b7f2-837fed4a0304„´precedence_heuristic §cell_idÙ$91a90dc6-4f33-403d-b7f2-837fed4a0304´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$9cf1da97-dcb0-4691-8597-44bc62dff257„´precedence_heuristic §cell_idÙ$9cf1da97-dcb0-4691-8597-44bc62dff257´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$86f8bb60-7e4c-4acd-af9c-ada0c589f7a5„´precedence_heuristic §cell_idÙ$86f8bb60-7e4c-4acd-af9c-ada0c589f7a5´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$4acece79-c67c-420e-a688-679d4c4dbe36„´precedence_heuristic §cell_idÙ$4acece79-c67c-420e-a688-679d4c4dbe36´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$78ccde0f-fdca-4db3-9af3-caa3a0963b23„´precedence_heuristic§cell_idÙ$78ccde0f-fdca-4db3-9af3-caa3a0963b23´downstream_cells_map�§PlutoUI‘Ù$b8b581e9-5085-4763-8f46-2aa718925635²upstream_cells_map€Ù$6a54d18f-45ec-4917-843e-d6af2660525c„´precedence_heuristic §cell_idÙ$6a54d18f-45ec-4917-843e-d6af2660525c´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$917f2df5-f63f-4937-b1e0-b60ed4351d9f„´precedence_heuristic §cell_idÙ$917f2df5-f63f-4937-b1e0-b60ed4351d9f´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$9d9b338e-c859-4089-aa27-40742dbfd054„´precedence_heuristic §cell_idÙ$9d9b338e-c859-4089-aa27-40742dbfd054´downstream_cells_map€²upstream_cells_map�¡:�¥Makie�¤lift�¨LinRange�ªGridLayout�¥cgrad�¨barplot!�¦ylims!�¢on�¡+�¦notify�¬Makie.Button�ªObservable�¦Figure�¤Axis�Ù$106e4592-7ddc-4388-b92d-d41933828032„´precedence_heuristic §cell_idÙ$106e4592-7ddc-4388-b92d-d41933828032´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�´cell_execution_orderÜ Ù$9d306b48-df32-11f0-b15f-7540889fd2b7Ù$78ccde0f-fdca-4db3-9af3-caa3a0963b23Ù$5b5f4616-0f66-455a-8e90-4f4027befc51Ù$d6c97e29-74b6-4be3-bf2a-0aba966e1eadÙ$4acece79-c67c-420e-a688-679d4c4dbe36Ù$2ed1866c-1d9a-4992-a98d-4492ebe8ca44Ù$048f54ba-45d1-49e2-b19d-7ef634c77cf0Ù$d353c065-7802-4f18-8492-008b860b9379Ù$106e4592-7ddc-4388-b92d-d41933828032Ù$9cf1da97-dcb0-4691-8597-44bc62dff257Ù$2220f4b9-02bd-4540-a32e-124b90cd3033Ù$13c42895-ad10-4f99-adc2-a3f371987d56Ù$91a90dc6-4f33-403d-b7f2-837fed4a0304Ù$9d9b338e-c859-4089-aa27-40742dbfd054Ù$df840868-75d4-4687-8556-19eeab1e4115Ù$9e86e965-7a3e-43bc-930a-5d916273770fÙ$b8b581e9-5085-4763-8f46-2aa718925635Ù$86f8bb60-7e4c-4acd-af9c-ada0c589f7a5Ù$96269a69-e678-4a9f-87c2-6215032b42d1Ù$b1658a17-b59f-4c35-b7a0-1503e377c731Ù$b496ac83-b3c7-4758-994e-7534abc56932Ù$a6937e90-5714-4023-aaf5-02909c53daa7Ù$774f1c41-7a84-401a-950c-466cf05fcd92Ù$6d79f301-b6b4-40be-b48e-e194466b5170Ù$917f2df5-f63f-4937-b1e0-b60ed4351d9fÙ$6a54d18f-45ec-4917-843e-d6af2660525c´last_hot_reload_timeË ©shortpath«WGLMakie.jl®process_status¥ready¤pathÙC/home/fons/featured-slider-server/featured_fix/src/plot/WGLMakie.jlpluto_version¦v1.0.0®last_save_timeËAÚ†7â1¶ªcell_orderÜ Ù$5b5f4616-0f66-455a-8e90-4f4027befc51Ù$d6c97e29-74b6-4be3-bf2a-0aba966e1eadÙ$4acece79-c67c-420e-a688-679d4c4dbe36Ù$2ed1866c-1d9a-4992-a98d-4492ebe8ca44Ù$048f54ba-45d1-49e2-b19d-7ef634c77cf0Ù$d353c065-7802-4f18-8492-008b860b9379Ù$106e4592-7ddc-4388-b92d-d41933828032Ù$9cf1da97-dcb0-4691-8597-44bc62dff257Ù$2220f4b9-02bd-4540-a32e-124b90cd3033Ù$9d306b48-df32-11f0-b15f-7540889fd2b7Ù$13c42895-ad10-4f99-adc2-a3f371987d56Ù$91a90dc6-4f33-403d-b7f2-837fed4a0304Ù$9d9b338e-c859-4089-aa27-40742dbfd054Ù$df840868-75d4-4687-8556-19eeab1e4115Ù$78ccde0f-fdca-4db3-9af3-caa3a0963b23Ù$9e86e965-7a3e-43bc-930a-5d916273770fÙ$b8b581e9-5085-4763-8f46-2aa718925635Ù$86f8bb60-7e4c-4acd-af9c-ada0c589f7a5Ù$96269a69-e678-4a9f-87c2-6215032b42d1Ù$b1658a17-b59f-4c35-b7a0-1503e377c731Ù$b496ac83-b3c7-4758-994e-7534abc56932Ù$a6937e90-5714-4023-aaf5-02909c53daa7Ù$774f1c41-7a84-401a-950c-466cf05fcd92Ù$6d79f301-b6b4-40be-b48e-e194466b5170Ù$917f2df5-f63f-4937-b1e0-b60ed4351d9fÙ$6a54d18f-45ec-4917-843e-d6af2660525cjulia_version§v1.12.4±published_objects€¥nbpkgНinstall_time_nsÎwWÑ߬instantiatedòinstalled_versions„¨WGLMakie§0.13.10§PlutoUI¦0.7.81Ù!__internal_julia_manifest_version¦1.12.4¸__internal_julia_version¦1.12.4°terminal_outputsƒ¨WGLMakieÚ&
[0m[1mWaiting for other notebooks to finish Pkg operations...[22m
[90m===[39m
[0m[1mResolving...[22m
[90m===[39m
[36m[1m Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_mcstztzpqr/Project.toml`
[36m[1m Manifest[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_mcstztzpqr/Manifest.toml`
[0m[1mInstantiating...[22m
[90m===[39m
[0m[1mPrecompiling...[22m
[90m===[39mªnbpkg_syncÚ&
[0m[1mWaiting for other notebooks to finish Pkg operations...[22m
[90m===[39m
[0m[1mResolving...[22m
[90m===[39m
[36m[1m Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_mcstztzpqr/Project.toml`
[36m[1m Manifest[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_mcstztzpqr/Manifest.toml`
[0m[1mInstantiating...[22m
[90m===[39m
[0m[1mPrecompiling...[22m
[90m===[39m§PlutoUIÚ&
[0m[1mWaiting for other notebooks to finish Pkg operations...[22m
[90m===[39m
[0m[1mResolving...[22m
[90m===[39m
[36m[1m Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_mcstztzpqr/Project.toml`
[36m[1m Manifest[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_mcstztzpqr/Manifest.toml`
[0m[1mInstantiating...[22m
[90m===[39m
[0m[1mPrecompiling...[22m
[90m===[39m§enabled÷restart_recommended_msgÀ´restart_required_msgÀbusy_packages�¶waiting_for_permissionÂÙ,waiting_for_permission_but_probably_disabled«cell_inputsÞ Ù$048f54ba-45d1-49e2-b19d-7ef634c77cf0„§cell_idÙ$048f54ba-45d1-49e2-b19d-7ef634c77cf0¤codeÚUlet
figurewidth = 600
fig = Figure(size=(figurewidth,300))
ax = Axis(fig[1, 1], limits = (0, 600, -2, 2))
hidexdecorations!(ax)
t = Observable(0.0)
points = lift(t) do t
x = range(t-1, t+1, length = 500)
@. sin(x) * sin(2x) * sin(4x) * sin(23x)
end
lines!(ax, points, color = (1:500) .^ 2, linewidth = 2, colormap = [(:blue, 0.0), :blue])
gl = GridLayout(fig[2, 1], tellwidth = false)
Label(gl[1, 1], "Live Update")
toggle = Toggle(gl[1, 2], active = false)
on(fig.scene.events.tick) do tick
toggle.active[] || return
t[] += tick.delta_time
end
fig
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$b1658a17-b59f-4c35-b7a0-1503e377c731„§cell_idÙ$b1658a17-b59f-4c35-b7a0-1503e377c731¤codeÙ–md"The following cell automatically updates the content of the observable `val_obs` each time we move the slider. In turn, it updates the plot below."¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$774f1c41-7a84-401a-950c-466cf05fcd92„§cell_idÙ$774f1c41-7a84-401a-950c-466cf05fcd92¤codeÙämd"""
!!! warning
The code must be separated into four cells as above (slider, definition of the observable, update of the observable, plot). *In fact, the definition of the observable could be included in the "plot cell".*
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$a6937e90-5714-4023-aaf5-02909c53daa7„§cell_idÙ$a6937e90-5714-4023-aaf5-02909c53daa7¤codeÙ�begin
x = @lift(@. exp(-$val_obs/8)*cos($val_obs))
y = @lift(@. exp(-$val_obs/8)*sin($val_obs))
lines(x,y, axis=(;limits=(-1,2,-1,1)))
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$b496ac83-b3c7-4758-994e-7534abc56932„§cell_idÙ$b496ac83-b3c7-4758-994e-7534abc56932¤code¶val_obs[] = 0:0.01:val¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$df840868-75d4-4687-8556-19eeab1e4115„§cell_idÙ$df840868-75d4-4687-8556-19eeab1e4115¤codeÙ*md"## Integration in Pluto (with PlutoUI)"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$d353c065-7802-4f18-8492-008b860b9379„§cell_idÙ$d353c065-7802-4f18-8492-008b860b9379¤code¬md"## Makie"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$5b5f4616-0f66-455a-8e90-4f4027befc51„§cell_idÙ$5b5f4616-0f66-455a-8e90-4f4027befc51¤codeÙ/md"# Interactivity and animations via WGLMakie"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$13c42895-ad10-4f99-adc2-a3f371987d56„§cell_idÙ$13c42895-ad10-4f99-adc2-a3f371987d56¤codeÚmd"We recommend to put all the commands related to the Makie animation (usually starting with `fig = Figure(...)` and ending with `fig`) in a `let ... end` block. Hence all variables defined in the block are defined locally. In particular they are not reactive and the same variable name (e.g. `fig`, `ax`, etc.) can be used in several `let ... end` blocks.
!!! warning
Since some interactive components (e.g. `Slider`) are also exported by other packages (e.g. PlutoUI), you may need to write `Makie.Slider` to avoid ambiguity.
"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$6d79f301-b6b4-40be-b48e-e194466b5170„§cell_idÙ$6d79f301-b6b4-40be-b48e-e194466b5170¤codeÚNmd"
!!! note
The plot above is internaly updated thanks to the `Observable` type. It is not replotted each time `val` is modified. Compare with:
```
let
val_non_obs = 0:0.01:val
x = @. exp(- val_non_obs/8) * cos(val_non_obs)
y = @. exp(- val_non_obs/8) * sin(val_non_obs)
lines(x,y, axis=(;limits=(-1,2,-1,1)))
end
```
"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$d6c97e29-74b6-4be3-bf2a-0aba966e1ead„§cell_idÙ$d6c97e29-74b6-4be3-bf2a-0aba966e1ead¤codeÙ–md"""
!!! warning
This notedbook cannot be viewed statically online (as a featured notebook), you need to **Run this notebook** to see the plots.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$2220f4b9-02bd-4540-a32e-124b90cd3033„§cell_idÙ$2220f4b9-02bd-4540-a32e-124b90cd3033¤codeÙimd"Makie animations can be integrated almost seamlessly into Pluto notebooks via the `WGLMakie` backend."¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$96269a69-e678-4a9f-87c2-6215032b42d1„§cell_idÙ$96269a69-e678-4a9f-87c2-6215032b42d1¤codeÙ!val_obs = Observable(0.0:0.1:0.0)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$2ed1866c-1d9a-4992-a98d-4492ebe8ca44„§cell_idÙ$2ed1866c-1d9a-4992-a98d-4492ebe8ca44¤codeÚmd"Here is an example of interactive plot. You can push the *Live Update* button to get a moving curve. It is taken from [Makie documentation on toggles](https://docs.makie.org/stable/reference/blocks/toggle). *You may have to manually run the cell below.*"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$9d306b48-df32-11f0-b15f-7540889fd2b7„§cell_idÙ$9d306b48-df32-11f0-b15f-7540889fd2b7¤code®using WGLMakie¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$b8b581e9-5085-4763-8f46-2aa718925635„§cell_idÙ$b8b581e9-5085-4763-8f46-2aa718925635¤codeÙ'@bind val PlutoUI.Slider(0.0:0.01:40.0)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$9e86e965-7a3e-43bc-930a-5d916273770f„§cell_idÙ$9e86e965-7a3e-43bc-930a-5d916273770f¤codeÙåmd"There is an intermediate solution that combines Makie's `Observable` with PlutoUI's interactivity. Here is a simple example with a `PlutoUI.Slider` where we want to plot some values generated from a range between 0 and `val`."¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$91a90dc6-4f33-403d-b7f2-837fed4a0304„§cell_idÙ$91a90dc6-4f33-403d-b7f2-837fed4a0304¤codeÙ’md"Finally, here is another animation example taken from [Makie documentation on buttons](https://docs.makie.org/stable/reference/blocks/button)."¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$9cf1da97-dcb0-4691-8597-44bc62dff257„§cell_idÙ$9cf1da97-dcb0-4691-8597-44bc62dff257¤codeÙ-md"## Integration in Pluto (without PlutoUI)"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$86f8bb60-7e4c-4acd-af9c-ada0c589f7a5„§cell_idÙ$86f8bb60-7e4c-4acd-af9c-ada0c589f7a5¤codeÚ'md"Then, we initialize an `Observable`. The argument `0.0:0.1:0.0` is only used for initialization. It only has to respect the type that we want, i.e. `StepRange` here. *In case you don't know the type in advance, you could force it to be `Any` via `val_obs = Observable{Any}(0)` for instance.*"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$4acece79-c67c-420e-a688-679d4c4dbe36„§cell_idÙ$4acece79-c67c-420e-a688-679d4c4dbe36¤codeÚLmd"""The most natural way to put interactivity within a **Pluto notebook** is to use the `@bind` macro from `PlutoUI.jl` coupled with Pluto reactivity. The [PlutoUI notebook](https://featured.plutojl.org/basic/plutoui.jl) gives lots of examples to elaborate on.
The objective of the present notebook is to present an alternative using the [Makie](https://docs.makie.org/stable/) ecosystem.
!!! warning
The `Makie` package is a powerful plotting package, but it takes a while to install and precompile. Therefore, this notebook will be a bit slow to start the first time you run it.
"""¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$78ccde0f-fdca-4db3-9af3-caa3a0963b23„§cell_idÙ$78ccde0f-fdca-4db3-9af3-caa3a0963b23¤codeusing PlutoUI¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$6a54d18f-45ec-4917-843e-d6af2660525c„§cell_idÙ$6a54d18f-45ec-4917-843e-d6af2660525c¤codeÚþmd"There are two main drawbacks when using *pure* Makie animations:
1. it relies on the heavy Makie ecosystem (long to precompile and run),
2. it is harder to get global dependencies in your animations than if you are using PlutoUI and reactivity.
Hence, if you plan to share your notebook you should avoid to use Makie.
However, if you plan to produce slides for a presentation, using Makie is a great option. It gives high quality plots and highly customizable animations that will make your slides shine.
"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$917f2df5-f63f-4937-b1e0-b60ed4351d9f„§cell_idÙ$917f2df5-f63f-4937-b1e0-b60ed4351d9f¤code±md"## Conclusion"¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$9d9b338e-c859-4089-aa27-40742dbfd054„§cell_idÙ$9d9b338e-c859-4089-aa27-40742dbfd054¤codeÚõlet
fig = Figure()
ax = Axis(fig[1, 1])
fig[2, 1] = buttongrid = GridLayout(tellwidth = false)
counts = Observable([1, 4, 3, 7, 2])
buttonlabels = [lift(x -> "Count: $(x[i])", counts) for i in 1:5]
buttons = buttongrid[1, 1:5] = [Makie.Button(fig, label = l) for l in buttonlabels]
for i in 1:5
on(buttons[i].clicks) do n
counts[][i] += 1
notify(counts)
end
end
barplot!(counts, color = cgrad(:Spectral)[LinRange(0, 1, 5)])
ylims!(ax, 0, 20)
fig
end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$106e4592-7ddc-4388-b92d-d41933828032„§cell_idÙ$106e4592-7ddc-4388-b92d-d41933828032¤codeÚÐmd"If you are not familiar with Makie, here is Makie's [basic tutorial](https://docs.makie.org/stable/tutorials/getting-started) dealing with static single plots and Makie's [advanced tutorial](https://docs.makie.org/stable/tutorials/layout-tutorial) dealing with layouts of multiple plots.
If you are familiar with Makie for static plots, but not for animations, have a look at Makie's [animation tutorial](https://docs.makie.org/stable/explanations/animation)."¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedënotebook_idÙ$e5caf330-b8ac-11f1-82d0-6dbeda4cd89d«in_temp_dir¨metadata�«frontmatter…¦author‘‚¤name±Julien Chevallier£url»https://github.com/jucheval¥imageÙ\https://image2url.com/r2/default/gifs/1772474106000-b9bdee0b-91fe-4d82-af83-2bc1fec8c734.gif¥title¸Animations with WGLMakie¤tags“visualisation©animation¨plotting«descriptionÙCAn introduction to animations with or without the use of PlutoUI.jl