Preface

Plotting and visualizing data is an everyday skill for researchers and data scientists that is helpful for discovering and communicating insights. Additionally, adding interactivity to our visualization tasks enhances data exploration steps. At the same time, interactive visualizations and animations allow us to share more compelling stories from data. This book will teach you how to perform such tasks using the Julia programming language and the packages in its ecosystem.

The Julia plotting ecosystem is a breath of fresh air for plotting and data visualization, a new ecosystem to explore. This book will guide you through that exploration. First, it will introduce you to the basics of Julia and the Plots package. This package allows you to write plotting specifications that you can later render using different backends without changing your code. For example, you can render the same plot using Plotly for JavaScript-based interactivity or PGFPlotsX for generating a LaTeX-based publication-quality output. These are only two examples; in this book, we will discuss the different backends and learn how to choose the most appropriate for your task. Then, the book will also introduce you to Makie. This plotting library shines because of its native interactivity support and GPU-powered three-dimensional plots. Another interesting feature of those plotting packages is their extensibility. Plots and Makie offer recipe systems to allow us to create new plot types and specify how to display data types. The Julia package ecosystem intensively uses these recipes to define the different visualizations we will explore in the book’s second part, for example, to create classical statistical plots and visualize networks and geographically distributed data. Finally, in the book’s third part, we will present the aspects needed to customize your plots to make them look as you wish. In that section, we will explore another key feature of Plots and Makie: their powerful layout system. Those systems allow for programmatically creating plot panels and figures in an easy way.

By the end of this book, you will be able to visualize data and create interactive plots with Julia. You will know how to make classical plots and develop new plot types that best suit your use case.

Who this book is for

This book is for researchers and data analysts looking to explore Julia’s data visualization capabilities. It will also suit people wanting to acquire or improve plotting skills with the language. This book will support anyone developing static or interactive plots with Julia. You need basic computer programming knowledge to follow this book. However, the book does not require previous experience with the Julia language as it introduces Julia’s syntax and concepts as needed. Therefore, this book could also help people who are new to the language and that are willing to start exploring its plotting ecosystem.

What this book covers

Chapter 1, An Introduction to Julia for Data Visualization and Analysis, introduces the minimal Julia concepts needed to create basic plots using the Plots package, in particular, heatmaps and scatter and line plots. To that end, it will introduce basic data types that serve as input for plotting functions. This chapter will cover the use of packages and how to work with reproducible project environments. It also presents different Julia developing environments. Among those, we will start working with Pluto notebooks—heavily used through this book. All in all, this chapter offers the essential knowledge needed for the rest of the book.

Chapter 2, The Julia Plotting Ecosystem, presents the Julia plotting ecosystem, showing the different plotting libraries available and their relation. Among those packages, we will focus on Plots and Makie—this chapter introduces the latter—and their backends. After reading this chapter, you should be able to choose the most appropriate plotting library for your data visualization task.

Chapter 3, Getting Interactive Plots with Julia, describes how to get interactive plots using Julia. First, this chapter will go through different kinds of interactivity, highlighting the packages that allow you to access them. Among those packages, it presents the Observables package, an essential package in the Julia ecosystem for developing interactive visualizations. Then, this chapter goes deeper into reaching interactivity with Plots and Makie packages and their backends. After that, it introduces the Interact and PlutoUI packages to create interactive visualizations using Jupyter and Pluto notebooks, respectively. Finally, it presents tools to publish and share interactive visualizations using dashboards, web pages, and simple graphical user interfaces.

Chapter 4, Creating Animations, teaches you how to create animations with Plots and Makie. Also, it will help you determine when it could be helpful to produce animations. Finally, this chapter introduces Javis, a drawing library to generate animations in Julia.

Chapter 5, Introducing the Grammar of Graphics, covers the Julia plotting packages based on or inspired by The Grammar of Graphics, namely, Gadfly, VegaLite, and AlgebraOfGraphics. It will also introduce the DataFrames package, crucial for working with tidy data in Julia. Therefore, this chapter is essential for starting to analyze and visualize data.

Chapter 6, Creating Statistical Plots, shows you how to create the most common statistical plots using the different Julia libraries. In particular, this chapter will focus on Plots, Makie, and Gadfly. This chapter, together with the previous one, gives you an excellent primer to start performing data analysis and data visualization tasks with Julia.

Chapter 7, Visualizing Graphs, introduces the LightGraph and MetaGraphs packages to work with graphs and networks. Then, it shows us how to visualize them using GraphPlot, GraphRecipes, and GraphMakie.

Chapter 8, Visualizing Geographically Distributed Data, showcases how to visualize geographically distributed data with choropleth plots using Plots and GeoMakie. After that, the chapter will examine the creation of street maps using the OpenStreetMapX package.

Chapter 9, Plotting Biological Data, shows different packages that allow the visualization and analysis of biological data. In particular, the chapter focuses on visualizing phylogenetic trees, multiple sequence alignments, and protein structures. Finally, it shows how to create a dashboard using DashBio to develop interactive visualizations for biological data.

Chapter 10, The Anatomy of a Plot, explains a plot’s different components. That knowledge is needed to understand the organization of the attributes for customizing those components. To that end, the chapter introduces the different terminology that Plots, Makie, and Gadfly use for their plot elements.

Chapter 11, Defining Plot Layouts to Create Figure Panels, describes how to compose multiple plots into one. To that end, it will first present the powerful Plots layout system. After that, it will introduce the layout capabilities of Makie and Gadfly.

Chapter 12, Customizing Plot Attributes – Axes, Legends, and Colors, covers some interesting attributes to customize your plots—focusing on the Plots package. The chapter first gives you the tools needed for exploring the Plots and Makie attributes without leaving your Julia session. Then, it shows you how to insert LaTeX equations into your Plots and Makie figures. After that, this chapter will teach us how to customize text elements, axes, legends, and colors.

Chapter 13, Designing Plot Themes, shows how to define plot themes—needed to reuse customizations—or use the predefined ones. In particular, this chapter will discuss theming in Plots, Makie, and Gadfly.

Chapter 14, Designing Your Own Plots – Plot Recipes, introduces the Plots and Makie recipe systems to create custom visualizations or whole new plot types. The chapter also shows how to draw shapes and create custom markers using Plots.

To get the most out of this book

Most of this book’s chapters need a computer with Julia and a web browser installed and access to the internet. All the code examples have been tested on a Linux machine using Julia 1.6, as this was the LTS version when writing the book. Since the chapters were written at different times, package versions can change from chapter to chapter. Because of that, the following table offers version ranges for some packages:

This book touches on many packages, and this list only shows the ones used in most chapters. To ensure reproducibility, we provide the code used to create the book examples in the GitHub repository of this book. Each chapter folder contains the project environment used to write the examples; you can activate those environments as described in Chapter 1, An Introduction to Julia for Data Visualization and Analysis, if you find errors when using more recent versions of the packages. Also, each Pluto notebook saves its project environment inside; therefore, you can run the Pluto notebook files in the GitHub repo to ensure you are using identical package versions. Note that Julia packages follow the Semantic Versioning (SemVer) specification. Therefore, you can expect this code to work with any recent release of Plots version 1. However, note that for packages in version 0, any change in the middle number can be breaking.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Note that this book requires you to have basic computer programming knowledge—experience with any high-level language will be enough. You do not need to know Julia, as the book will introduce the concepts and syntax required to follow the examples. However, note that this book will not be enough if you don’t have experience with Julia and are looking to learn the language. In such a case, complementing this book with other sources could be beneficial. Also, note that this book focuses on visualization aspects and won’t discuss the mathematical and statistical foundations behind plot types. Therefore, you will get the most out of some chapters in the book’s second part if you have some basic knowledge of those subjects—but that is not a requirement to follow the text.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Interactive-Visualization-and-Plotting-with-Julia. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/i4MaE.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The plotmap function from OpenStreetMapX can take the MapData object and plot the stored map.”

A block of code is set as follows:

plot([sin, cos], 0:0.1:2pi, 
labels=["sin" "cos"],
linecolor=[:orange :green],
linewidth=[1, 5])

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

plt = plot(data_block.geometry, 
fill_z = permutedims(data_block.deaths),
colorbar_title = "cholera deaths",
seriescolor = :Greys_3, 
linecolor = :darkgray, 
framestyle = :none)

Any command-line input or output is written as follows:

julia script.jl

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Click New in the Edit environment variable window.”

Tips or Important Notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Interactive Visualization and Plotting with Julia, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.107.60