For questions related to labeling plot data points or bar labels.
Questions tagged [plot-annotations]
156 questions
225
votes
11 answers
How to display the value on horizontal bars
I generated a bar plot, how can I display the value of the bar on each bar?
Current plot:
What I am trying to get:
My code:
import os
import numpy as np
import matplotlib.pyplot as plt
x = [u'INFO', u'CUISINE', u'TYPE_OF_PLACE', u'DRINK',…

Franck Dernoncourt
- 77,520
- 72
- 342
- 501
187
votes
3 answers
Seaborn showing scientific notation in heatmap for 3-digit numbers
I'm creating a heatmap from a pandas pivot_table as below:
table2 = pd.pivot_table(df,values='control',columns='Year',index='Region',aggfunc=np.sum)
sns.heatmap(table2,annot=True,cmap='Blues')
It creates a heat map as shown below. You can see the…

cigrainger
- 2,096
- 2
- 15
- 11
158
votes
3 answers
Putting text in top left corner of matplotlib plot
How can I put text in the top left (or top right) corner of a matplotlib figure, e.g. where a top left legend would be, or on top of the plot but in the top left corner? E.g. if it's a plt.scatter(), then something that would be within the square…
user248237
142
votes
5 answers
How to place inline labels in a line plot
In Matplotlib, it's not too tough to make a legend (example_legend(), below), but I think it's better style to put labels right on the curves being plotted (as in example_inline(), below). This can be very fiddly, because I have to specify…

Alex Szatmary
- 3,431
- 3
- 21
- 30
88
votes
7 answers
How do I use matplotlib autopct?
I'd like to create a matplotlib pie chart which has the value of each wedge written on top of the wedge.
The documentation suggests I should use autopct to do this.
autopct: [ None | format string |
format function ]
If not None, is a…

Kim
- 3,316
- 5
- 25
- 28
79
votes
3 answers
Text box with line wrapping
Is it possible to display text in a box through Matplotlib, with automatic line breaks? By using pyplot.text(), I was only able to print multi-line text that flows beyond the boundaries of the window, which is annoying. The size of the lines is…

Eric O. Lebigot
- 91,433
- 48
- 218
- 260
70
votes
3 answers
automatically position text box in plot
Is there a way of telling pyplot.text() a location like you can with pyplot.legend()?
Something like the legend argument would be excellent:
plt.legend(loc="upper left")
I am trying to label subplots with different axes using letters (e.g.…

Anake
- 7,201
- 12
- 45
- 59
60
votes
1 answer
percent label position in pie chart
Is there a way to change the default position of the percent label in a matplotlib pie chart?
Here is an example pie chart:
Which I have created using:
plt.pie(sizes, labels=labels, colors=colors, explode=explode, autopct='%1.0f%%')
Now I don't…

Daniel
- 8,179
- 6
- 31
- 56
52
votes
6 answers
How to add percentages on top of grouped bars
Given the following count plot how do I place percentages on top of the bars?
import seaborn as sns
sns.set(style="darkgrid")
titanic = sns.load_dataset("titanic")
ax = sns.countplot(x="class", hue="who", data=titanic)
For example for "First" I…

collarblind
- 4,549
- 13
- 31
- 49
51
votes
4 answers
How to space overlapping annotations
I want to annotate the bars in a graph with some text but if the bars are close together and have comparable height, the annotations are above ea. other and thus hard to read (the coordinates for the annotations were taken from the bar position and…

BandGap
- 1,745
- 4
- 19
- 26
51
votes
4 answers
How to put text outside of plots
I am plotting two time series and computing varies indices for them.
How to write these indices for these plots outside the plot using annotation or text in python?
Below is my code
import matplotlib.pyplot as plt
obs_graph=plt.plot(obs_df['cms'],…

dsbisht
- 1,025
- 4
- 13
- 24
51
votes
2 answers
How does one insert statistical annotations (stars or p-values)
This seems like a trivial question, but I've been searching for a while and can't seem to find an answer. It also seems like something that should be a standard part of these packages. Does anyone know if there is a standard way to include…

cancerconnector
- 1,225
- 2
- 14
- 21
50
votes
5 answers
unique plot marker for each plot
I have a loop where i create some plots and I need unique marker for each plot. I think about creating function, which returns random symbol, and use it in my program in this way:
for i in xrange(len(y)):
plt.plot(x, y [i], randomMarker())
but…

user983302
- 1,377
- 3
- 14
- 23
45
votes
4 answers
How to avoid overlapping of labels & autopct in a pie chart
My Python code is:
values = [234, 64, 54,10, 0, 1, 0, 9, 2, 1, 7, 7]
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul','Aug','Sep','Oct', 'Nov','Dec']
colors = ['yellowgreen', 'red', 'gold', 'lightskyblue',
…

Adithya
- 1,687
- 3
- 19
- 34
43
votes
3 answers
Different font sizes in the same annotation of matplotlib
I need to annotate a pylab rectangle with few data lines - which are of different length.
Searching through the matplotlib documentation, and Googling, I could not find a way to give different parts of an annotation different sizes.
The following…

user1850727
- 569
- 2
- 6
- 9