Visualization¶
In this module, you will learn how to make a figure that a reader can read easily: which figure type to use, how to design the figure, which colors to use, and which tool to use.
A plot with the default settings of a plotting library is not ready for a report. The labels, the size of the text, the colors, and the file type all need a decision. Each page answers one question about a figure, and one page changes a default plot into a figure for a report, step by step.
Learning objectives¶
- Choose a figure type by what you want to show
- Plot data that has many columns with a pair plot and with PCA
- Apply five principles to a figure: a clear message, labels, only the elements you need, readable fonts, and vector or high-resolution files
- Turn a default Matplotlib plot into a figure for a report, and export it as PDF and PNG
- Choose a color map by the class of your data, and check it in gray scale
- Find color-blind friendly color maps with Scicolor
- Make figures with Matplotlib and seaborn, an interactive figure with Plotly, and a small dashboard with Streamlit
- Use an AI coding agent with figure skills to write plotting code, and check the figures that it makes
Pages¶
| Page | What it covers |
|---|---|
| Figure types | A table that leads from what you want to show to a figure type; data with many columns: the pair plot, the pair plot with color, and dimension reduction with PCA; one link each for t-SNE, UMAP, and maps |
| Figure design principles | Five principles: think about your message, label the figure, keep it simple, make the fonts readable, and use vector or high-resolution files; a worked example that changes a default plot into a figure for a report in five steps |
| Color | What a scientific color map is; how to check a color map in gray scale; the classes and types of color maps, and which class fits which data; how to find a color map with Scicolor; the contrast between text and background |
| Plotting tools | Matplotlib and when to use it; two seaborn examples, a joint plot and an annotated heatmap; an interactive Plotly figure that you can try on the page; a Streamlit script for a small dashboard |
| Plotting with AI coding agents | What an AI coding agent does without guidance; what a skill is; the two YangLabKit skills for figures and how to install them; the same six figures with and without the skills; what you still check yourself |
Notebooks¶
Each notebook holds the code of one page and runs in Colab without setup. The Pair plots and PCA notebook and the Seaborn and Plotly notebook each download one small CSV file when they run. The Figure for a report notebook and the Color maps notebook use the Scicolor package, and their first code cell installs it in Colab.
The Streamlit script of the Plotting tools page is not in a notebook, because it runs as a program on your own computer.
Tools¶
| Tool | What it is for | In this module |
|---|---|---|
| Matplotlib (Python) | The basic plotting library of Python, with almost every figure type | Matplotlib, and the worked example on Figure design principles |
| seaborn (Python) | Built on Matplotlib; it makes common statistical figures with one call | Seaborn, and the pair plots on Figure types |
| Plotly (Python) | Interactive figures for a web page | Plotly |
| Streamlit (Python) | Not a plotting library; it turns a Python script into a web page with controls and figures | Streamlit |
| ggplot2 (R) | A plotting library for the language R | Not covered |
Every figure in this module is made with Matplotlib, seaborn, or Plotly. The notebooks also use Scicolor, a Python package of color maps for scientific figures, and scikit-learn for PCA.
Related¶
- Hypothesis testing and statistical analysis, whose pages have the code for the histogram, the box plot, the violin plot, the CDF, the scatter plot, and the 2D histogram
- Network analysis, the module for plots of the connections between accounts