Plotting with seaborn using the matplotlib object-oriented interface

It depends a bit on which seaborn function you are using. The plotting functions in seaborn are broadly divided into two classes “Axes-level” functions, including regplot, boxplot, kdeplot, and many others “Figure-level” functions, including relplot, catplot, displot, pairplot, jointplot and one or two others The first group is identified by taking an explicit ax argument … Read more

Stacked Bar Chart with Centered Labels

The following method is more succinct, and easily scales. Putting the data into a pandas.DataFrame is the easiest way to plot a stacked bar plot. Using pandas.DataFrame.plot.bar(stacked=True), or pandas.DataFrame.plot(kind=’bar’, stacked=True), is the easiest way to plot a stacked bar plot. This method returns a matplotlib.axes.Axes or a numpy.ndarray of them. Since seaborn is just a … Read more

How to have clusters of stacked bars with python (Pandas)

I eventually found a trick (edit: see below for using seaborn and longform dataframe): Solution with pandas and matplotlib Here it is with a more complete example : import pandas as pd import matplotlib.cm as cm import numpy as np import matplotlib.pyplot as plt def plot_clustered_stacked(dfall, labels=None, title=”multiple stacked bar plot”, H=”/”, **kwargs): “””Given a … Read more

How to add hovering annotations in matplotlib

It seems none of the other answers here actually answer the question. So here is a code that uses a scatter and shows an annotation upon hovering over the scatter points. import matplotlib.pyplot as plt import numpy as np; np.random.seed(1) x = np.random.rand(15) y = np.random.rand(15) names = np.array(list(“ABCDEFGHIJKLMNO”)) c = np.random.randint(1,5,size=15) norm = plt.Normalize(1,4) … Read more