News

New paper!

Tuesday, March 12, 2019

Python visualisation cheat sheet

Seaborn

Specify the color of plots for each category
parameter: palette
>>> palette = {"category name 0":"C0","category name 1":"C1",...}
C0, C1... refers to the 0th, 1st, ... color in the selected palette.
The category names have to be matched with the names in hue.


Matplotlib.pyplot

Move legend out of the plot frame
>>> plt.legend(bbox_to_anchor=(1.1,0.5,1,0.5), loc=2, borderaxespad=0.)
*This works for legend created by seaborn as well.

In Jupyter notebook, the legend created by the above method may be cut off with the setting of %matplotlib notebook. To adjust the location and size of the figure,
>>> fig.subplots_adjust(left=0.1,right=0.8,bottom=0.3,wspace=0.3,hspace=0.1)