bondscell_results$c8b63bfc-3ef3-41b5-9f9f-7b59a5c0cce2queued¤logsrunning¦outputbodyٲ

Of course, we can also pass the z-coordinates of the data (z) as the third argument to the heatmap function.

mimetext/htmlrootassigneelast_run_timestampAQ!persist_js_state·has_pluto_hook_features§cell_id$c8b63bfc-3ef3-41b5-9f9f-7b59a5c0cce2depends_on_disabled_cells§runtime̵published_object_keysdepends_on_skipped_cells§errored$a5c86153-8430-4336-a82f-c671b2c63eb5queued¤logsrunning¦outputbodyK

Defining a custom seriestype

We can define a custom seriestype by creating a new struct and defining a recipe for it. Here we define a custom seriestype SemiLogy that plots the y-axis on a logarithmic scale.

mimetext/htmlrootassigneelast_run_timestampAQ!=.persist_js_state·has_pluto_hook_features§cell_id$a5c86153-8430-4336-a82f-c671b2c63eb5depends_on_disabled_cells§runtimevpublished_object_keysdepends_on_skipped_cells§errored$86a17ea2-ce2c-44a5-ad69-b30b280dfb41queued¤logslinemsgsize(f.(x', y)) = (3, 20) text/plaincell_id$86a17ea2-ce2c-44a5-ad69-b30b280dfb41kwargsidPlutoRunner_d1acb81efileP/home/runner/.julia/packages/Pluto/esC4R/src/runner/PlutoRunner/src/io/stdout.jlgroupstdoutlevelLogLevel(-555)running¦outputbodyH mimeimage/svg+xmlrootassigneelast_run_timestampAQDpersist_js_state·has_pluto_hook_features§cell_id$86a17ea2-ce2c-44a5-ad69-b30b280dfb41depends_on_disabled_cells§runtimeM}published_object_keysdepends_on_skipped_cells§errored$8cabb3ac-bd6f-496c-84b2-bb536ba0ff54queued¤logsrunning¦outputbody

To run this notebook plots.jl locally, copy and paste the following into your Julia REPL:

using Pkg; Pkg.activate(temp=true); Pkg.add("Pluto")
BASE_URL = "https://raw.githubusercontent.com/tensor4all/T4APlutoExamples/refs/heads/main/pluto_notebooks/"
notebook = "plots.jl"
url = joinpath(BASE_URL, notebook)
using Pluto; Pluto.run(notebook=download(url))
mimetext/htmlrootassigneelast_run_timestampAQ dcpersist_js_state·has_pluto_hook_features§cell_id$8cabb3ac-bd6f-496c-84b2-bb536ba0ff54depends_on_disabled_cells§runtime)published_object_keysdepends_on_skipped_cells§errored$b1c45986-eb23-42aa-ba27-8269686ad626queued¤logsrunning¦outputbody(

We can draw multiple functions on a same plot pane using plot! function. The following example demonstrates plotting the sine function $y = \sin(x)$ for $x \in [-\pi, \pi]$.

mimetext/htmlrootassigneelast_run_timestampAQ persist_js_state·has_pluto_hook_features§cell_id$b1c45986-eb23-42aa-ba27-8269686ad626depends_on_disabled_cells§runtime<Ƶpublished_object_keysdepends_on_skipped_cells§errored$f1871cd6-8d8c-4e38-920b-c3f145513b22queued¤logsrunning¦outputbodyH mimeimage/svg+xmlrootassigneelast_run_timestampAQpersist_js_state·has_pluto_hook_features§cell_id$f1871cd6-8d8c-4e38-920b-c3f145513b22depends_on_disabled_cells§runtimej4ʵpublished_object_keysdepends_on_skipped_cells§errored$679f9791-df49-47f6-b5e0-562737f265b5queued¤logsrunning¦outputbody

Introduction to Plots.jl

This guide provides an introduction to Plots.jl, a powerful and flexible plotting package for Julia. Plots.jl is a widely used Julia package for data visualization.

mimetext/htmlrootassigneelast_run_timestampAQ persist_js_state·has_pluto_hook_features§cell_id$679f9791-df49-47f6-b5e0-562737f265b5depends_on_disabled_cells§runtimeRpublished_object_keysdepends_on_skipped_cells§errored$0ece0753-f329-43e6-9a34-99eeb7345cf4queued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampAQE*persist_js_state·has_pluto_hook_features§cell_id$0ece0753-f329-43e6-9a34-99eeb7345cf4depends_on_disabled_cells§runtime ?published_object_keysdepends_on_skipped_cells§errored$5e630874-2ce5-4a8a-9cc0-c2474a9a6fa3queued¤logsrunning¦outputbodyȀ mimeimage/svg+xmlrootassigneelast_run_timestampAQpersist_js_state·has_pluto_hook_features§cell_id$5e630874-2ce5-4a8a-9cc0-c2474a9a6fa3depends_on_disabled_cells§runtimeM/published_object_keysdepends_on_skipped_cells§errored$aeab03ea-5947-4088-b60e-d1b32e98d164queued¤logsrunning¦outputbodyȉ mimeimage/svg+xmlrootassigneelast_run_timestampAQ`persist_js_state·has_pluto_hook_features§cell_id$aeab03ea-5947-4088-b60e-d1b32e98d164depends_on_disabled_cells§runtime#published_object_keysdepends_on_skipped_cells§errored$83905cd7-4548-482b-9514-3b9ef2d99e67queued¤logsrunning¦outputbody

Additionally, we can provide x-coordinates (x) and y-coordinates (y) as arguments to the plot function to create custom plots.

mimetext/htmlrootassigneelast_run_timestampAQ persist_js_state·has_pluto_hook_features§cell_id$83905cd7-4548-482b-9514-3b9ef2d99e67depends_on_disabled_cells§runtime1npublished_object_keysdepends_on_skipped_cells§errored$9e90b55e-863a-4d6f-91d1-84e15ad1edd7queued¤logsrunning¦outputbodyٴ

Instead of specifying seriestype=:scatter, we can use the scatter or scatter! functions directly.

mimetext/htmlrootassigneelast_run_timestampAQ :persist_js_state·has_pluto_hook_features§cell_id$9e90b55e-863a-4d6f-91d1-84e15ad1edd7depends_on_disabled_cells§runtime,`published_object_keysdepends_on_skipped_cells§errored$25a968c0-4209-44e5-8e9a-ba580e0fbf4dqueued¤logsrunning¦outputbodyٖ

Heatmap

We can use the heatmap function to visualize a function on a two-dimensional domain.

mimetext/htmlrootassigneelast_run_timestampAQ!persist_js_state·has_pluto_hook_features§cell_id$25a968c0-4209-44e5-8e9a-ba580e0fbf4ddepends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored$5744c00e-ff55-4cff-b2ed-7079c341175equeued¤logsrunning¦outputbodyTC mimeimage/svg+xmlrootassigneelast_run_timestampAQpersist_js_state·has_pluto_hook_features§cell_id$5744c00e-ff55-4cff-b2ed-7079c341175edepends_on_disabled_cells§runtime}h/published_object_keysdepends_on_skipped_cells§errored$a76d8151-fb1d-4dcb-aaf7-eb7f3d3c1f9equeued¤logsrunning¦outputbodymimetext/plainrootassigneelast_run_timestampAQfpersist_js_state·has_pluto_hook_features§cell_id$a76d8151-fb1d-4dcb-aaf7-eb7f3d3c1f9edepends_on_disabled_cells§runtimeJfepublished_object_keysdepends_on_skipped_cells§errored$fa8f001c-e55b-457e-ae4e-80cf7aa1ffd7queued¤logsrunning¦outputbody4D mimeimage/svg+xmlrootassigneelast_run_timestampAQ^/'persist_js_state·has_pluto_hook_features§cell_id$fa8f001c-e55b-457e-ae4e-80cf7aa1ffd7depends_on_disabled_cells§runtimeⱵpublished_object_keysdepends_on_skipped_cells§errored$fe019b21-c774-49ff-981c-0487f0b07d42queued¤logsrunning¦outputbody~

To plot a given function, we can pass it as an argument to the plot function.

mimetext/htmlrootassigneelast_run_timestampAQ persist_js_state·has_pluto_hook_features§cell_id$fe019b21-c774-49ff-981c-0487f0b07d42depends_on_disabled_cells§runtime published_object_keysdepends_on_skipped_cells§errored$e44c2429-fc7c-4609-b27c-4b527a7b8440queued¤logsrunning¦outputbodyK mimeimage/svg+xmlrootassigneelast_run_timestampAQjpersist_js_state·has_pluto_hook_features§cell_id$e44c2429-fc7c-4609-b27c-4b527a7b8440depends_on_disabled_cells§runtimepublished_object_keysdepends_on_skipped_cells§errored±cell_dependencies$c8b63bfc-3ef3-41b5-9f9f-7b59a5c0cce2precedence_heuristic cell_id$c8b63bfc-3ef3-41b5-9f9f-7b59a5c0cce2downstream_cells_mapupstream_cells_map@md_strgetindex$a5c86153-8430-4336-a82f-c671b2c63eb5precedence_heuristic cell_id$a5c86153-8430-4336-a82f-c671b2c63eb5downstream_cells_mapupstream_cells_map@md_strgetindex$86a17ea2-ce2c-44a5-ad69-b30b280dfb41precedence_heuristic cell_id$86a17ea2-ce2c-44a5-ad69-b30b280dfb41downstream_cells_mapupstream_cells_map:sizeadjointBase.reprBaseBase.printlnheatmap+*conj@show$8cabb3ac-bd6f-496c-84b2-bb536ba0ff54precedence_heuristic cell_id$8cabb3ac-bd6f-496c-84b2-bb536ba0ff54downstream_cells_mapupstream_cells_map@md_strgetindex$b1c45986-eb23-42aa-ba27-8269686ad626precedence_heuristic cell_id$b1c45986-eb23-42aa-ba27-8269686ad626downstream_cells_mapupstream_cells_map@md_strgetindex$f1871cd6-8d8c-4e38-920b-c3f145513b22precedence_heuristic cell_id$f1871cd6-8d8c-4e38-920b-c3f145513b22downstream_cells_mapupstream_cells_map:heatmap+*$679f9791-df49-47f6-b5e0-562737f265b5precedence_heuristic cell_id$679f9791-df49-47f6-b5e0-562737f265b5downstream_cells_mapupstream_cells_map@md_strgetindex$0ece0753-f329-43e6-9a34-99eeb7345cf4precedence_heuristic cell_id$0ece0753-f329-43e6-9a34-99eeb7345cf4downstream_cells_mapsemilogy$0ece0753-f329-43e6-9a34-99eeb7345cf4$fa8f001c-e55b-457e-ae4e-80cf7aa1ffd7apply_recipeSemiLogy$0ece0753-f329-43e6-9a34-99eeb7345cf4semilogy!$0ece0753-f329-43e6-9a34-99eeb7345cf4upstream_cells_mapAnyendnothingbeginsemilogy$0ece0753-f329-43e6-9a34-99eeb7345cf4nextfloat@recipe$a76d8151-fb1d-4dcb-aaf7-eb7f3d3c1f9e===Symbolpush!AbstractDict+SemiLogy$0ece0753-f329-43e6-9a34-99eeb7345cf4@userplotsemilogy!$0ece0753-f329-43e6-9a34-99eeb7345cf4$5e630874-2ce5-4a8a-9cc0-c2474a9a6fa3precedence_heuristic cell_id$5e630874-2ce5-4a8a-9cc0-c2474a9a6fa3downstream_cells_mapupstream_cells_map:plotplot!randscatter!$aeab03ea-5947-4088-b60e-d1b32e98d164precedence_heuristic cell_id$aeab03ea-5947-4088-b60e-d1b32e98d164downstream_cells_mapupstream_cells_map:-plotplot!πcossin$83905cd7-4548-482b-9514-3b9ef2d99e67precedence_heuristic cell_id$83905cd7-4548-482b-9514-3b9ef2d99e67downstream_cells_mapupstream_cells_map@md_strgetindex$9e90b55e-863a-4d6f-91d1-84e15ad1edd7precedence_heuristic cell_id$9e90b55e-863a-4d6f-91d1-84e15ad1edd7downstream_cells_mapupstream_cells_map@md_strgetindex$25a968c0-4209-44e5-8e9a-ba580e0fbf4dprecedence_heuristic cell_id$25a968c0-4209-44e5-8e9a-ba580e0fbf4ddownstream_cells_mapupstream_cells_map@md_strgetindex$5744c00e-ff55-4cff-b2ed-7079c341175eprecedence_heuristic cell_id$5744c00e-ff55-4cff-b2ed-7079c341175edownstream_cells_mapupstream_cells_map:-plotπsin$a76d8151-fb1d-4dcb-aaf7-eb7f3d3c1f9eprecedence_heuristiccell_id$a76d8151-fb1d-4dcb-aaf7-eb7f3d3c1f9edownstream_cells_mapPlots@shorthandsLaTeXStrings@recipe$0ece0753-f329-43e6-9a34-99eeb7345cf4upstream_cells_map$fa8f001c-e55b-457e-ae4e-80cf7aa1ffd7precedence_heuristic cell_id$fa8f001c-e55b-457e-ae4e-80cf7aa1ffd7downstream_cells_mapupstream_cells_mapsemilogy$0ece0753-f329-43e6-9a34-99eeb7345cf4:^$fe019b21-c774-49ff-981c-0487f0b07d42precedence_heuristic cell_id$fe019b21-c774-49ff-981c-0487f0b07d42downstream_cells_mapupstream_cells_map@md_strgetindex$e44c2429-fc7c-4609-b27c-4b527a7b8440precedence_heuristic cell_id$e44c2429-fc7c-4609-b27c-4b527a7b8440downstream_cells_mapupstream_cells_mapplotsincell_execution_order$a76d8151-fb1d-4dcb-aaf7-eb7f3d3c1f9e$8cabb3ac-bd6f-496c-84b2-bb536ba0ff54$679f9791-df49-47f6-b5e0-562737f265b5$fe019b21-c774-49ff-981c-0487f0b07d42$e44c2429-fc7c-4609-b27c-4b527a7b8440$83905cd7-4548-482b-9514-3b9ef2d99e67$5744c00e-ff55-4cff-b2ed-7079c341175e$b1c45986-eb23-42aa-ba27-8269686ad626$aeab03ea-5947-4088-b60e-d1b32e98d164$9e90b55e-863a-4d6f-91d1-84e15ad1edd7$5e630874-2ce5-4a8a-9cc0-c2474a9a6fa3$25a968c0-4209-44e5-8e9a-ba580e0fbf4d$f1871cd6-8d8c-4e38-920b-c3f145513b22$c8b63bfc-3ef3-41b5-9f9f-7b59a5c0cce2$86a17ea2-ce2c-44a5-ad69-b30b280dfb41$a5c86153-8430-4336-a82f-c671b2c63eb5$0ece0753-f329-43e6-9a34-99eeb7345cf4$fa8f001c-e55b-457e-ae4e-80cf7aa1ffd7last_hot_reload_timeshortpathplots.jlprocess_statusreadypathL/home/runner/work/T4APlutoExamples/T4APlutoExamples/pluto_notebooks/plots.jlpluto_versionv0.20.3last_save_timeAQpCcell_order$8cabb3ac-bd6f-496c-84b2-bb536ba0ff54$679f9791-df49-47f6-b5e0-562737f265b5$a76d8151-fb1d-4dcb-aaf7-eb7f3d3c1f9e$fe019b21-c774-49ff-981c-0487f0b07d42$e44c2429-fc7c-4609-b27c-4b527a7b8440$83905cd7-4548-482b-9514-3b9ef2d99e67$5744c00e-ff55-4cff-b2ed-7079c341175e$b1c45986-eb23-42aa-ba27-8269686ad626$aeab03ea-5947-4088-b60e-d1b32e98d164$9e90b55e-863a-4d6f-91d1-84e15ad1edd7$5e630874-2ce5-4a8a-9cc0-c2474a9a6fa3$25a968c0-4209-44e5-8e9a-ba580e0fbf4d$f1871cd6-8d8c-4e38-920b-c3f145513b22$c8b63bfc-3ef3-41b5-9f9f-7b59a5c0cce2$86a17ea2-ce2c-44a5-ad69-b30b280dfb41$a5c86153-8430-4336-a82f-c671b2c63eb5$0ece0753-f329-43e6-9a34-99eeb7345cf4$fa8f001c-e55b-457e-ae4e-80cf7aa1ffd7published_objectsnbpkginstall_time_ns)Yinstantiatedòinstalled_versionsPlots1.40.9LaTeXStrings1.4.0terminal_outputsnbpkg_sync@ Instantiating... === Resolving... ===  No Changes to `/tmp/jl_sxD8Dy/Project.toml`  No Changes to `/tmp/jl_sxD8Dy/Manifest.toml` Precompiling... ===  Activating project at `/tmp/jl_sxD8Dy`Plots@ Instantiating... === Resolving... ===  No Changes to `/tmp/jl_sxD8Dy/Project.toml`  No Changes to `/tmp/jl_sxD8Dy/Manifest.toml` Precompiling... ===  Activating project at `/tmp/jl_sxD8Dy`LaTeXStrings@ Instantiating... === Resolving... ===  No Changes to `/tmp/jl_sxD8Dy/Project.toml`  No Changes to `/tmp/jl_sxD8Dy/Manifest.toml` Precompiling... ===  Activating project at `/tmp/jl_sxD8Dy`enabled÷restart_recommended_msgrestart_required_msgbusy_packageswaiting_for_permission,waiting_for_permission_but_probably_disabled«cell_inputs$c8b63bfc-3ef3-41b5-9f9f-7b59a5c0cce2cell_id$c8b63bfc-3ef3-41b5-9f9f-7b59a5c0cce2codezmd""" Of course, we can also pass the z-coordinates of the data (`z`) as the third argument to the `heatmap` function. """metadatashow_logsèdisabled®skip_as_script«code_folded$a5c86153-8430-4336-a82f-c671b2c63eb5cell_id$a5c86153-8430-4336-a82f-c671b2c63eb5codemd""" ## Defining a custom seriestype We can define a custom seriestype by creating a new struct and defining a [recipe](https://docs.juliaplots.org/stable/recipes/#recipes) for it. Here we define a custom seriestype `SemiLogy` that plots the y-axis on a logarithmic scale. """metadatashow_logsèdisabled®skip_as_script«code_folded$86a17ea2-ce2c-44a5-ad69-b30b280dfb41cell_id$86a17ea2-ce2c-44a5-ad69-b30b280dfb41codetlet x = 1:20 y = 1:3 f(x, y) = 2x + y @show size(f.(x', y)) z = f.(x', y) heatmap(x, y, z) endmetadatashow_logsèdisabled®skip_as_script«code_folded$8cabb3ac-bd6f-496c-84b2-bb536ba0ff54cell_id$8cabb3ac-bd6f-496c-84b2-bb536ba0ff54codezmd""" To run this notebook plots.jl locally, copy and paste the following into your Julia REPL: ```julia using Pkg; Pkg.activate(temp=true); Pkg.add("Pluto") BASE_URL = "https://raw.githubusercontent.com/tensor4all/T4APlutoExamples/refs/heads/main/pluto_notebooks/" notebook = "plots.jl" url = joinpath(BASE_URL, notebook) using Pluto; Pluto.run(notebook=download(url)) ``` """metadatashow_logsèdisabled®skip_as_script«code_folded$b1c45986-eb23-42aa-ba27-8269686ad626cell_id$b1c45986-eb23-42aa-ba27-8269686ad626codeٹmd""" We can draw multiple functions on a same plot pane using `plot!` function. The following example demonstrates plotting the sine function $y = \sin(x)$ for $x \in [-\pi, \pi]$. """metadatashow_logsèdisabled®skip_as_script«code_folded$f1871cd6-8d8c-4e38-920b-c3f145513b22cell_id$f1871cd6-8d8c-4e38-920b-c3f145513b22codeKlet x = 1:20 y = 1:3 f(x, y) = 2x + y heatmap(x, y, f) endmetadatashow_logsèdisabled®skip_as_script«code_folded$679f9791-df49-47f6-b5e0-562737f265b5cell_id$679f9791-df49-47f6-b5e0-562737f265b5codemd""" # Introduction to Plots.jl This guide provides an introduction to [Plots.jl](https://docs.juliaplots.org/stable/), a powerful and flexible plotting package for Julia. Plots.jl is a widely used Julia package for data visualization. """metadatashow_logsèdisabled®skip_as_script«code_folded$0ece0753-f329-43e6-9a34-99eeb7345cf4cell_id$0ece0753-f329-43e6-9a34-99eeb7345cf4code_begin # defines mutable struct `SemiLogy` and sets shorthands # `semilogy` and `semilogy!` @userplot SemiLogy @recipe function f(t::SemiLogy) x = t.args[begin] y = t.args[end] ε = nextfloat(0.0) yscale := :log10 # Adding ε avoids getting log10(0) from being -Inf (x, ε .+ y) end endmetadatashow_logsèdisabled®skip_as_script«code_folded$5e630874-2ce5-4a8a-9cc0-c2474a9a6fa3cell_id$5e630874-2ce5-4a8a-9cc0-c2474a9a6fa3codeflet x = 1:10 y = rand(10) plt = plot() plot!(x, y) scatter!(x, y, label="scatter", marker=:x) endmetadatashow_logsèdisabled®skip_as_script«code_folded$aeab03ea-5947-4088-b60e-d1b32e98d164cell_id$aeab03ea-5947-4088-b60e-d1b32e98d164codeٳlet x = -π:0.1:π y1 = sin.(x) y2 = cos.(x) plt = plot() # line plot plot!(plt, x, y1, label="sin") # scatter plot plot!(plt, x, y2, label="cos", seriestype=:scatter) endmetadatashow_logsèdisabled®skip_as_script«code_folded$83905cd7-4548-482b-9514-3b9ef2d99e67cell_id$83905cd7-4548-482b-9514-3b9ef2d99e67codeٍmd""" Additionally, we can provide x-coordinates (`x`) and y-coordinates (`y`) as arguments to the `plot` function to create custom plots."""metadatashow_logsèdisabled®skip_as_script«code_folded$9e90b55e-863a-4d6f-91d1-84e15ad1edd7cell_id$9e90b55e-863a-4d6f-91d1-84e15ad1edd7codeqmd""" Instead of specifying `seriestype=:scatter`, we can use the `scatter` or `scatter!` functions directly. """metadatashow_logsèdisabled®skip_as_script«code_folded$25a968c0-4209-44e5-8e9a-ba580e0fbf4dcell_id$25a968c0-4209-44e5-8e9a-ba580e0fbf4dcodelmd""" ## Heatmap We can use the `heatmap` function to visualize a function on a two-dimensional domain. """metadatashow_logsèdisabled®skip_as_script«code_folded$5744c00e-ff55-4cff-b2ed-7079c341175ecell_id$5744c00e-ff55-4cff-b2ed-7079c341175ecodeJlet x = -π:0.1:π y = sin.(x) # line plot plot(x, y, label="sin") endmetadatashow_logsèdisabled®skip_as_script«code_folded$a76d8151-fb1d-4dcb-aaf7-eb7f3d3c1f9ecell_id$a76d8151-fb1d-4dcb-aaf7-eb7f3d3c1f9ecodecbegin using Plots using Plots.RecipesBase: @recipe, @shorthands using LaTeXStrings endmetadatashow_logsèdisabled®skip_as_script«code_folded$fa8f001c-e55b-457e-ae4e-80cf7aa1ffd7cell_id$fa8f001c-e55b-457e-ae4e-80cf7aa1ffd7code(semilogy((-10:1:-7), 10.0 .^ (-10:1:-7))metadatashow_logsèdisabled®skip_as_script«code_folded$fe019b21-c774-49ff-981c-0487f0b07d42cell_id$fe019b21-c774-49ff-981c-0487f0b07d42codeYmd""" To plot a given function, we can pass it as an argument to the `plot` function. """metadatashow_logsèdisabled®skip_as_script«code_folded$e44c2429-fc7c-4609-b27c-4b527a7b8440cell_id$e44c2429-fc7c-4609-b27c-4b527a7b8440codeplot(sin)metadatashow_logsèdisabled®skip_as_script«code_folded«notebook_id$558c1c64-ae0d-11ef-030a-e9b821d95c74in_temp_dir¨metadata