Login with SSH key

Putting your password every time when you login into a server via SSH can be tiresome, especially if your password is long. One way to make life easier and also safer is to use SSH keys.

  1. In the terminal of your local machine, type in ssh-keygen. By default, the keys will be exported to ~/.ssh/id_rsa; using the default is okay in most cases, but if you have multiple keys want to avoid conflicts, you can change the destination. When it prompts you to enter a passphrase, you can just click Enter (empty passphrase) so that you don’t need to input anything when you login to a server use this key pair. But for better security, a passphrase is suggested.
  2. Copy your SSH public key into the server by ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]_address (change the path to the public key if you’ve saved it somewhere else). You’ll be prompted to enter your password at the server.
  3. Log in to the server by ssh [email protected]_address. You should be able to log in without having to enter your password! If it doesn’t work, check the permission of the ~/.ssh folder on your server. Only you should have write access to it. You can change its permission from your home folder by chmod 700 .ssh.

Change the default plotting settings for Jupyter Notebook / Lab

The combination of matplotlib (and seaborn) + Jupyter Notebook / Lab is a very popular where exploring and analyzing data. However, the default settings may not always satisfy all needs. Here, I listed several modifications that I introduced to the configuration files of Jupyter and Matplotlib to change their default behaviours.

Change default font size in Matplotlib

Some people like making figures’ fonts bigger so the audience can see them with ease, so here I’m are going to show you how to change the default font size for matplotlib:

  1. Locate the configuration file for matplotlib by running:
    1
    2
    import matplotlib
    print(matplotlib.matplotlib_fname())
  2. Open the file, locate the default settings that you want to override. I prepared several settings here as reference:
  • axes.labelsize: Font size for x and y labels
  • xtick.labelsize: Font size for ticks
  • legend.fontsize: Font size for legends
  1. If there’s # right before the option, it means this option is commented and will not be considered by matplotlib. So to make it working, remove the # first, and then change the value to the one you desired.
  2. Save the file, and go create new figures.

Make figures in Notebook more clear

For high-definition screen users, especially for people who are using Macbook and iMac, the inline figures shown up in Jupyter Notebook/ Lab can be very blurry, like the this one:

To solve this problem, you can execute the following command in the notebook that you want to get high-resolution figures:

1
%config InlineBackend.figure_format='retina'

Now output figures will be much more clear:

The major drawback for the above method is that you have to execute it every time you create a new Notebook. If you want Notebooks to produce high-def figures by default, you’ll need to modify the configuration files for IPython (which Notebooks use it to run actual codes):

  1. Check if you’ve already had a configuration (ipython_kernel_config.py) for IPython created before. For Linux and MacOS users, the file is usually located at ~/.ipython/profile_default, if you don’t know where it locates, you can use ipython locate to figure it out; if the file is not in this destination, you can run ipython profile create to create it.
  2. Add c.InlineBackend.figure_formats = ["retina"] or c.InlineBackend.figure_formats = ["svg"] to the end of this file (ipython_kernel_config.py).
  3. Kill your Jupyter Notebook / Lab, and rerun it.