For questions related to labeling plot data points or bar labels.
Questions tagged [plot-annotations]
156 questions
1
vote
2 answers
How to plot and annotate grouped bars
I have the following code
import numpy as np
import matplotlib.pyplot as plt
oct_data = [10, 24, 25, 30]
nov_data = [12, 42, 21, 78]
labels = ['Account_1', 'Account_2', 'Account_3', 'Account_4']
bar_width = 0.4
rect_1 = np.arange(0,…

Mornor
- 3,471
- 8
- 31
- 69
1
vote
2 answers
Pandas bar how to label desired values
d = {'X':[1,2,3,4],'A': [50,40,20,60], '% of Total in A':[29.4,23.5,11.8,35.3] , 'B': [25,10,5,15], '% in A' :[50,25,25,25]}
df = pd.DataFrame(d)
ax = df.plot(x='X',y="A", kind="bar")
df.plot(x='X', y="B", kind="bar", ax=ax,color='C2')
X A %…

Iwishworldpeace
- 478
- 4
- 12
1
vote
1 answer
How to make a horizontal stacked bar plot of values as percentage
I have a list of 0,1 in dataframe. How can I plot a percentage of bar plot in pandas or matplotlib, that would have in the legend 1,0 and written annotation of percentage of the 1,0 compare to the whole list?
import pandas as pd
import…

Jerzy
- 155
- 1
- 8
1
vote
2 answers
Can you calculate the size of a text annotation?
I would like to calculate the size (height and width) of a text label in matplotlib in data coordinates so I can move it in a certain direction by its own size. Ideally I would like to know the size before I draw it.
import matplotlib.pylab as…

nickponline
- 25,354
- 32
- 99
- 167
1
vote
1 answer
How to remove NaN values from matshow 2D plot and format labels as percentages
I am plotting some 2D array data as a map with a color scale and I have some NaN values that I don't want to show up. I need these values to show up as plain white squares and for the formatting to be in percentage style. Here is what I have so…

MUD
- 121
- 1
- 13
1
vote
1 answer
How to add multiple data labels in a bar chart
I have two grouped bar charts of value changes between cases for two systems among 3 groups as below. Here I was able to add data labels to the bars using the code below (figure produced attached)
What I want to do is on top (or bottom for the…

user496181
- 141
- 7
1
vote
1 answer
How to annotate grouped bar plot with percent by hue/legend group
I want to add percentage on the top of bars according to the hue. That means all the red and blue bars are equal to 100% respectively.
I can make the blue bars equal to 100%, but the red bars can't. Which parts should be modified?
Imports and Sample…

UnicornKKYY
- 75
- 6
1
vote
1 answer
How to add annotations in the diagonal squares of a PairGrid
I want to implement a 5 number summary along the diagonal of a Python Seaborn PairGrid. I tried df.describe() along the diagonal but it did not work. A sample of what I am looking for is the picture at the bottom of this link…

Daniel Poh
- 129
- 1
- 10
1
vote
1 answer
How to annotate a bar plot with a bracket
I want to place a bracket over a fraction of my data in a histogram to appear similar to the figure below. Can anyone show me how to do this with my code?
Age demographic sizes in the UK population
import pandas as pd
import matplotlib.pyplot as…

syn_bio_delta
- 25
- 7
1
vote
1 answer
How to show variable names as labels on the x-axis of a histogram?
I have a problem plotting a histogram of the results of my project (3 variables). The results do not appear as desired.
def plot():
kwargs = dict(alpha=0.9, bins=100)
plt.hist(Accuracy_of_NB, **kwargs, color='g', label='NB')
…

mohdsh334
- 21
- 5
1
vote
2 answers
Add label values to bar chart and line chart
I have created a bar chart and a line chart using two different y-axes for the following dataframe.
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({'DXC':['T1', 'H1', 'HP', 'T1_or_H1_or_HP'],
'Count':…

veg2020
- 956
- 10
- 27
1
vote
2 answers
How to annotate bar chart with values different to those from get_height()
I solved my own question after a long and failed search, so I'm posting the question here and the answer immediately below.
The goal: plot percentages but annotate raw counts.
The problem: you can annotate the bars with your plotted data (in my…

KMunro
- 348
- 4
- 14
1
vote
1 answer
Pie Chart Mathtext Label/Autopct
So I've been fooling around with the pyplot pie() function and it works well and all except for when I try to use mathtext in the wedge labeling (as in the autopct labeling, where I'd like the number, a \pm (+-) sign and some relevant number). Is it…

Scheme stepper
- 43
- 1
- 6
0
votes
0 answers
How to extend plot area to keep text inside of plot area without clipping
I have a plot with a long text string that was inserted (string not determined by me, so I can't shorten it):
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
lines = [[(0, 1), (1, 1)], [(2, 3), (3, 3)], [(1, 2),…

con
- 5,767
- 8
- 33
- 62
0
votes
1 answer
How to make stacked bar chart with annotations
I have the following dataframe:
df = pd.DataFrame(data = {'id' : ['hbo', 'hbo', 'hbo', 'fox','fox','fox', 'NBC', 'NBC', 'NBC'],
'device': ['laptop', 'tv', 'cellphone','laptop', 'tv', 'cellphone','laptop', 'tv', 'cellphone'],
…

Beans On Toast
- 903
- 9
- 25