Skip to content

Instantly share code, notes, and snippets.

@fomightez
Last active February 6, 2024 15:48
Show Gist options
  • Save fomightez/e7c5a1fa4cf95e80a6902249fd8927ee to your computer and use it in GitHub Desktop.
Save fomightez/e7c5a1fa4cf95e80a6902249fd8927ee to your computer and use it in GitHub Desktop.
Style tips for plotting with Python for SO question https://stackoverflow.com/q/77944909/8508004

Style tips for plotting with Python for SO question https://stackoverflow.com/q/77944909/8508004

In general, I opt for Seaborn when plotting with Python. It is built on top of Matplotlib and handles a lot of the style stuff better than default Matplotlib.

A good initial starting point to getting it close to Excel is to use Seaborn's 'whitegrid' that you set with Seaborn's set_style() method.
So to kick things off, it is common to do:

import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style("whitegrid")

In order to have full control of things in the plot usually you will also need matplotlib-level access to handle so I generally import that along with seaborn rigth at the start, too.

Seaborn has excellent documentation here.

I found what I thought was a better match to Excel's blue than the default blue in your view is cerulean See https://xkcd.com/color/rgb/ .
More about Color specifying xkcd colors in Matplotlib & related packages is at https://matplotlib.org/stable/users/explain/colors/colors.html .

You can specify thickness of an sns.lineplot() with linewidth, such as linewidth=1.9, as part of the parameters you supply in the parantheses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment