Part 1: Multiple Plots

Using make_subplots takes the following steps:

(1) generate a figure via make_subplots function

(2) add trace via add_trace function

(3) update_layout is used to reset the image setting

Notes on make_subplots

  • specs is an important parameter in make_subplots , and it will determine the type of plots we want to have, for example, if we want to have pie plot, then we should write specs=[[{'type':'pie'}]]
  • subplot_titles is used to denote the title of each subplots

Part 2: Basic Plot Element

Part 2.1: Pie

go.Pie

Reference


Part 1: path searching

pathlib.Path(target_dir).glob("**/*")

if only folders/sub-folders

pathlib.Path(target_dir).glob('**')
  • all files/folders in current directory
pathlib.Path(target_dir).glob('*')
  • all files/folders in the second current directory
pathlib.Path(target_dir).glob('*/*')
  • search for a certain type of files

(1) global search including sub-directories

my_list = pathlib.Path(my_dir).rglob("*.png")

(2) only search in current directory

my_list = pathlib.Path(my_dir).glob("*.png")

Part 2: file manipulation

 from pathlib import Path 
my_path = Path.cwd() / 'python' / 'libpath' / "a.txt"

assert my_path.exists(), print(my_path)
my_path.unlink()

Part 3: path relation

pathlib.Path(my_path).joinpath(*argv)

Part 1: Immutable object

If two variables refer to immutable objects that have equal values (a == b is True), in practice it rarely matters if they refer to copies or are aliases referring to the same object because the value of an immutable object does not change, with one exception. The exception is immutable collections such as tuples and frozensets: if an immutable collection holds references to mutable items, then its value may actually change when the value of a mutable item changes. In practice, this scenario is not so common. …


Part 1: Introduction

In order to represent data in Python, we have the following options:

  • write a class that organize data
  • use named tuple / dictionary or their enhanced versions (from typing)
  • employ dataclass

We recommend to use dataclass as it provides a lot of possibilities.

However, using dataclass can be problematic from the software engineering perspective:

These are classes that have fields, getting and setting methods for fields, and nothing else.Such classes are dumb data holders and are often being manipulated in far too much detail by other classes.

— from Refactoring of Martin Fowler and Kent Beck

The main idea of…


Part 1: Introduction

In this blog I keep track of what I have configured my new Ubuntu machine for machine learning projects.

Part 2: System

(1) Operating system

Ubuntu 18.04 LTS

(2) Settings from previous Ubuntu machine

  • .ssh
  • .bashrc
  • .hgrc

(3) GPU

a) check the GPU information by using

`sudo lshw -c video`, and you will know what kind of GPU you have in your PC.

b) `sudo ubuntu-drivers devices` find the GPU driver version that is recommended

c) install the recommended version `sudo apt install nvidia-driver-version-number` or use `sudo ubuntu-drivers autoinstall`, letting the computer choose the recommended GPU driver version for you. …


Part 1: Introduction

It may happen that sometimes we may need to install Ubuntu packages without Internet connection. Such a scenario happens to me one day when my desktop needs to compile the wireless adapter driver program using make command before it can connect with the Internet. However, the native Ubuntu 18.04 system does not contain build-essential package. So I have to find a way to install it offline. In this article, I record the way how I successfully install this Ubuntu package.

Part 2: Step-by-step Guild-line

Step 1: in a Ubuntu machine that can connect with Internet, download the docker Ubuntu system that you have installed…


Table of Contents

· Part 1: Introduction
· Part 2: Package Installation
· Part 3: Docs Structure
· Part 4: Documentation Website Generation
· Part 4: Mkdocs Enhancement
· Reference

Part 1: Introduction

In the past few years, I have been using Markdown to write technical notes and then I use Mkdocs to organize them. Here is a summary of my experience.

Part 2: Package Installation

Software Installation

Additional Plugins

  • pip install mkdocs-jupyter makes mkdocs supports jupyter-notebook
  • pip install mkdocs-material and pip install mkdocstrings make mkdocs support Python code documentation

Part 3: Docs Structure

File/Folder Structure

├── docs │…


Image for post
Image for post

Part 1: Project Configuration

There are several ways to configure projects:

  • Command-line arguments

Part 1: Factory and Abstract Factory

The Abstract Factory Pattern is a creational pattern that adds an abstract layer over multiple factory method implementations.

Image for post
Image for post

The Abstract Factory pattern differs from the Factory Pattern in that it returns Factories, rather than objects of concrete class.

Part 2: Observer

The observer pattern is a software design pattern in which an object, called the subject or observable, manages a list of dependents, called observers, and notifies them automatically of any internal state changes, and calls one of their methods.


Part 1: What is exception?

- BaseException
|----------Exception
|-------ArithmeticError
- GeneratorExit
- KeyboardInterupt
- SystemExit
  • Custom exceptions
raise NotImplementedError

Part 2: How to handle exceptions properly?

def get_restaurant_recommendation(path):
try:
config = get_config(path)
user = config["user"]
except FileNotFoundException:
logging.error("VERY UNINFORMATIVE INFORMATION")
raise
except JSONDecodeError:
logging.error("VERY UNINFORMATIVE INFORMATION")
raise
except KeyError:
user = "default_user"
else:
pass
final:
pass
candidates = get_relevant_restaurants(user)
pick_best_restaurants(candidates)
  • suppress exceptions
try:
os.remove('somefile.py')
except FileNotFoundError:
pass
OR
from contexlib import suppress
with suppress(FileNotError):
os.remove('somefile.py')
+-- AttributeError```

Ma Jianglin

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store