Learntofish's Blog

A blog about math, physics and computer science

My weight loss plotted using Pandas and Matplotlib

Posted by Ed on November 16, 2019


Here is the source code:

import pandas as pd
import matplotlib.pyplot as plt

def plot_weight_loss():
    df = pd.read_csv('weight_loss.csv')
    weights = df['weightInKg']
    dates = df['date']
    plt.plot(dates, weights, 'ro--')
    plt.ylabel('weight in kg')
    plt.title('Weight loss')

    # https://matplotlib.org/3.1.1/gallery/ticks_and_spines/ticklabels_rotation.html
    # You can specify a rotation for the tick labels in degrees or with keywords.
    plt.xticks(dates, rotation='vertical')
    # Pad margins so that markers don't get clipped by the axes
    # Tweak spacing to prevent clipping of tick-labels


def main():

    ['bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark-palette', 'seaborn-dark', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'seaborn', 'Solarize_Light2', 'tableau-colorblind10', '_classic_test']

if __name__ == '__main__':

And here is the content of the file ‘weight_loss.csv’:


Posted in Uncategorized | Leave a Comment »

Free Web Development Courses

Posted by Ed on October 29, 2019

  1. FreeCodeCamp
  2. TheOdinProject
  3. FullStackOpen (by University of Helsinki, more courses here)
  4. FullStackPython

Posted in Uncategorized | Leave a Comment »

Korean phrases – Introduce yourself

Posted by Ed on February 16, 2019

1. 안녕하세요 (Annyeong-Hase-Yo) – Hello.
2. 저는 Peter 입니다 (Jeo-Neun Peter Im-Ni-Da) – My name is Peter.
3. 감사합니다 (Kam-Sa-Ham-Ni-Da) – Thank you.

Posted in Uncategorized | Tagged: , , | Leave a Comment »

Interview with Linus Torvalds

Posted by Ed on October 6, 2018

Check out this fascinating interview with Linus Torvalds, the inventor of Linux and Git:

Posted in programming | Tagged: , , | Leave a Comment »

Clean code posts by Anas Shekhamis

Posted by Ed on October 1, 2018

Check out these posts on Clean Code by Anas Shekhamis.

Posted in programming | Tagged: | Leave a Comment »

Data Science and Artificial Intelligence with Python

Posted by Ed on September 30, 2018

Check out Chris Albon’s website on data science and artificial intelligence containing many examples in Python.

Posted in programming | Tagged: , , | Leave a Comment »

Python style guide

Posted by Ed on September 30, 2018

Check out this style guide for Python from The Hitchhiker’s guide to Python. It recommends installing pycodestyle and autopep8 to format your code.

Posted in programming | Tagged: , | Leave a Comment »

Java static nested class vs inner class

Posted by Ed on September 30, 2018

In Java there are two types of nested classes:

  1. If the nested class is declared static, then it is referred to as static nested class.
  2. If the nested class is declared non static, then it is referred to as inner class.

The following code shows a class OuterClass that contains both a static nested class and an inner class:

public class OuterClass {
	private String outerClassAttribute = "Hello from outer class.";
	static class StaticNestedClass {
		public void printHello() {
			System.out.println("Hello from the static nested class.");

	class InnerClass {
		public void printHello() {
			System.out.println("Hello from the inner class.");
		public void printOuterClassAttribute() {


Here is an example that illustrates how to instantiate objects of the respective classes. Notice that the inner class has access to the member variable outerClassAttribute of the outer class.

public class OuterClassExample {
	public static void main(String[] args) {

	public static void staticNestedClassDemo() {
		OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();

	public static void innerClassDemo() {
		OuterClass outerObject = new OuterClass();
		OuterClass.InnerClass innerObject = outerObject.new InnerClass();


And here is the output:

Hello from the static nested class.

Hello from the inner class.
Hello from outer class.


  1. Nested classes (from the official Java tutorial by Oracle)
  2. Java inner class and static nested class (StackOverflow discussion)

Posted in programming | Tagged: , , | Leave a Comment »

Endure boredom and increase attention span

Posted by Ed on September 30, 2018

Here is an interesting video by Derek from his channel Veritasium on the scientific benefits of boredom.

And here is a video by CollegeHumor that I found via the reddit thread How can I get my attention span back? When watching it you may feel the urge to jump to different website just to saturate the hunger for new information.

I’m guilty of this. Last week I caught myself having 50 tabs open in the browser! After realizing this problem I have deleted several reddit subscriptions.

Posted in health | Leave a Comment »

Java Eclipse IDE shortcuts

Posted by Ed on September 29, 2018

Here are some shortcuts for the Eclipse IDE that I use when programming in Java:

Ctrl + Space : Auto-Complete, e.g. type Hash and hit Ctrl + Space. This will open a box with suggestions you can choose from to auto complete.

Ctrl + Shift + T : Search for a type / class. Example: You want check the code for the class SimpleDateFormat. Hit the shortcut and enter SimpleDateFormat. The box then returns suggestions for classes with this name (there could be multiple classes with the same name, but in different packages). It even suffices to enter the capital letters in SimpleDateFormat, i.e. you search for SDF.

Ctrl + Alt + H : Display call hierarchy. Mark a method or class and hit the shortcut. This will display the places where your method or class is used.

Ctrl + D : Deletes the line that your cursor is in.

Alt + Shift + A : Activates multi line editing. Hit the shortcut, hold shift and use the directional keys to mark the lines you want to edit. Hit the shortcut again to get out of the multi line editing mode.

Ctrl + 1 : Displays suggestions. Example: you want to get the size of a list called myList and store it in the variable n.

final List myList = new ArrayList();

If you now type

n = myList.size();

and hit the shortcut Ctrl + 1, then it will suggest the correct type for n.

Ctrl + Shift + O : Organizes the imports. Example: You get an error because of a missing import. Then you can use this shortcut to use the required imports. You can also remove unused imports with this shortcut.

Ctrl + Shift + F : Formats the code.

Ctrl + O : Displays methods and attributes of the current class.

Ctrl + L : Go to line.

F3 : Mark a variable or class name and hit this shortcut to jump to its declaration.


Vogella Eclipse PDF cheatsheet

Youtube video by Team MAST

Java Eclipse Shortcuts: Tips and Tricks for the Eclipse Java IDE

Quora article

Posted in programming | Tagged: , , | Leave a Comment »