#Visualization

Linear regression is a fundamental method in data analysis to understand the relationship between two variables. Here, I summarize four reusable Python functions for performing and visualizing linear fitting:

  1. Matplotlib: with and without intercept
  2. Plotly: with and without intercept

All methods:

  • Drop NaN values in x and y
  • Plot a scatter graph
  • Fit a linear line
  • Annotate the equation and correlation coefficient (R)

Read More

In this post, I document the full procedure for turning a personal Python project into a public package, available on both GitHub and the Python Package Index (PyPI).

As a demonstration, I create a small package named PalAniSh (Palette of Animation of Shanghai), which extracts and displays color palettes from classical Chinese animations produced by the Shanghai Animation Film Studio.

Read More

I’m writing today about downloading, handling, and plotting satellite derived air pollution maps with cartopy and fiona using Python. One key task in this post is to clip a raster-like (2-d array) dataset with a polygon in pure Python environment (i.e., no need for ArcGIS or QGIS GUI-based software).

The satellite sensor can offer critical supplementary data of several atmospheric species, e.g., SO2, NO2, PM2.5. Comparaing to ground-based monitoring which might be sparse in some areas (e.g., Africa, South America, oceans), the satellite observation offers a full picture for better understanding the spatiotemporal patterns of some air pollutants.

Below is an excerpt of a NO2 column maps within Chengyu urabn agglomeration in China.

Read More

Welcome to my collection of Python scripts and code snippets for everyday use. This document contains a variety of scripts and code snippets that can be used to automate repetitive tasks, process data, and perform various other operations. Whether you are a beginner or an experienced Python programmer, this collection of scripts and code snippets will provide you with useful tools and shortcuts for your everyday work.

In this document, you will find code snippets and scripts for tasks such as:

  • Data processing
  • File manipulation
  • Web scraping
  • Automating tasks
  • And more!

This document is organized into sections for easy navigation, so you can quickly find the script or code snippet that you need. Many of them were collected from stackoverflow.

On 2022.03.31, I re-organize all the scripts into Python 3.x version and post again.
On 2023.02.12, I edited the whole content with help from ChatGPT

Read More

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×