plot-annotations

How to put value over bars when creating many barplots with a loop

How to put value over bars when creating many barplots with a loop Question: How can I put the value over the bars when creating many plots with a loop. The code I am using years = [twenty,twentyone,twentytwo,twentythree] for year in years: plt.ylim(0, 60) ax = sns.barplot(data=year, errorbar=None) ax.set_xticklabels(ax.get_xticklabels(), rotation=45, horizontalalignment=’right’) for i in ax.containers: …

Total answers: 1

Plotting country labels with cartopy

Plotting country labels with cartopy Question: I am trying to create a map overview using cartopy, but for some reason cannot figure out how to plot the names of the countries shown on the map. My function looks like this: import matplotlib.pyplot as plt import cartopy.crs as ccrs import cartopy.feature as cfeature from cartopy.mpl.gridliner import …

Total answers: 1

Adding bar labels shrinks dodged bars in seaborn.objects

Adding bar labels shrinks dodged bars in seaborn.objects Question: I am trying to add text labels to the top of a grouped/dodged bar plot using seaborn.objects. Here is a basic dodged bar plot: import seaborn.objects as so import pandas as pd dat = pd.DataFrame({‘group’:[‘a’,’a’,’b’,’b’], ‘x’:[‘1′,’2′,’1′,’2’], ‘y’:[3,4,1,2]}) (so.Plot(dat, x = ‘x’, y = ‘y’, color = …

Total answers: 1

Create a stacked bar plot of percentages and annotate with count

Create a stacked bar plot of percentages and annotate with count Question: I have this data (df) and I get their percentages (data=rel) and plotted a stacked bar graph. Now I want to add values (non percentage values) to the centers of each bar but from my first dataframe. My code for now: import pandas …

Total answers: 2

How to annotate each lmplot facet by hue group or combined data

How to annotate each lmplot facet by hue group or combined data Question: I’m trying to add annotations to lmplots in a FacetGrid (r and p values for each regression) but the plots have two regression lines because I’m using "hue", and therefore I get two annotations that are stacked on top of each other. …

Total answers: 1

How to add annotations in the diagonal squares of a pairplot

How to add annotations in the diagonal squares of a pairplot Question: I’ve created a graph based on the iris dataset, but my Professor wants it to look a particular way. Their example has the diagonals labeled by the attribute. I don’t see the option to edit the diagonal in that way in seaborn’s pairplot …

Total answers: 2

How to make a multi-level chart column label by hue

How to make a multi-level chart column label by hue Question: This is a continuation of this question. But now I have a bar-chart with hue. Here’s what I have: df = pd.DataFrame({‘age’: [’20-30′, ’20-30′, ’20-30′, ’30-40′, ’30-40′, ’30-40′, ’40-50′, ’40-50′, ’40-50′, ’50-60′, ’50-60′, ’50-60′], ‘expenses’:[’50$’, ‘100$’, ‘200$’, ’50$’, ‘100$’, ‘200$’, ’50$’, ‘100$’, ‘200$’, ’50$’, …

Total answers: 1

How to make a multi-level chart column label

How to make a multi-level chart column label Question: I stopped at this point: df = pd.DataFrame({‘id’: [1, 2, 3], ‘users’: [40, 2, 51], ‘buyers’: [15, 1, 29], ‘percentage’: [37.5000, 50.0000, 56.8627]}) fig, ax = plt.subplots(figsize=(10, 6)) # Plot the all users sns.barplot(x=’id’, y=’users’, data=df, palette=’Blues’, edgecolor=’grey’, alpha=0.7) # Plot the buyers sns.barplot(x=’id’, y=’buyers’, data=df, …

Total answers: 1

How to label bars with multiple custom values

How to label bars with multiple custom values Question: I have this dataframe rules count percentage groups weight A 15 24% 1 10 B 5 2% 2 30 C 25 50% 3 50 I have the following code: sns.set(rc={‘figure.figsize’:(18,9.5)}) plots = sns.barplot(x="rules", y="count", data=df, hue=df[‘groups’], dodge=False) percentage = df[‘percentage’].tolist() weight = df[‘weight’].tolist() patches = plots.patches …

Total answers: 1