Questions tagged [plot-annotations]

For questions related to labeling plot data points or bar labels.

156 questions
3
votes
0 answers

How to add text in between two lines adaptively using matplotlib?

How to add text in between two lines adaptively like this fig below? of course, you can use ax.annotate. However, when the line changes, you have to find once again the coordinate to put the text... I know there is fill_between function for…
user3737702
  • 591
  • 1
  • 10
  • 17
3
votes
1 answer

How can I keep an annotation within the visible window?

How can I keep an annotation within the window, in Matplotlib? Basically, I want to fix this so that the yellow box will be visible: Which was generated by this mcve: from matplotlib import pyplot point = pyplot.scatter(0, 0) s = '''This is some…
Justin
  • 24,288
  • 12
  • 92
  • 142
3
votes
1 answer

Smart automatic positioning of text box in plot

I'm following the recipe given in this answer by Joe Kington to position a text box in a corner of a plot, using the matplotlib.offsetbox.AnchoredText() module. This works perfectly if I know where I want to position the text box, but what if I want…
Gabriel
  • 40,504
  • 73
  • 230
  • 404
2
votes
1 answer

How to correct coordinate shifting in ax.annotate

I tried to annotate a line plot with ax.annotate as follows. import numpy as np import matplotlib.pyplot as plt x_start = 0 x_end = 200 y_start = 20 y_end = 20 fig, ax = plt.subplots(figsize=(5,5),dpi=600) ax.plot(np.asarray([i for i in…
Johnny Tam
  • 423
  • 4
  • 16
2
votes
1 answer

Why do my hover annotations have NaN instead of my values?

import yfinance as yf import mplfinance as mpf import matplotlib.pyplot as plt import matplotlib.patches as mpatches import pandas as pd import numpy as np # Dates to get stock data start_date = "2020-01-01" end_date = "2023-06-15" # Fetch Tesla…
Damian
  • 29
  • 5
2
votes
1 answer

How to annotate scatter points plotted with the prince library

I am using the library prince in order to perform Correspondence Analysis from prince import CA My contingency table dummy_contingency looks like this: {'v1': {'0': 4.479591836734694, '1': 75.08163265306122, '2': 1.1020408163265305, '3':…
2
votes
0 answers

Draggable annotation box when inside a subfigure

I want to create a draggable annotation box with Matplotlib. However, my ax is defined on a SubFigure object rather than a Figure. The following short code shows how the text box cannot be dragged in that case (unless it's located "outside" the plot…
2
votes
2 answers

Include notes in seaborn barplot

I have a barplot that I would like to include a note at the bottom. The current code is shown below import pandas as pd import numpy as np import seaborn as sns import matplotlib.pyplot as plt from matplotlib.ticker import PercentFormatter data =…
Stephen Okiya
  • 315
  • 1
  • 8
2
votes
2 answers

How can I add text to the same position in multiple matplotlib plots with different axis scales?

I have ~20 plots with different axes, ranging from scales of 0-1 to 0-300. I want to use plt.text(x,y) to add text to the top left corner in my automated plotting function, but the changing axis size does not allow for this to be automated and…
Tom
  • 377
  • 3
  • 13
2
votes
1 answer

Adding bar labels shrinks dodged bars in seaborn.objects

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'], …
2
votes
2 answers

How to change annotations in one column of seaborn heatmap

I plotted a heatmap using seaborn as shown below. I want to change the highlighted column into "Thousands K and Million M" values (shown in the table below). I tried it doing it but the column is changing into string and giving me an error when I am…
Javed Ali
  • 139
  • 1
  • 10
2
votes
1 answer

How to label bars with multiple custom values

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…
rnv86
  • 790
  • 4
  • 10
  • 22
2
votes
1 answer

Adding the x-axis values to the peaks in the graph

Dear StackOverflow family, I have been trying to put the x-axis values next to, or at the top of the peaks that are detected in the graph. Basically, first I used the function to find the peaks in the spectrum. Then, I want to use these x-axis…
vdu16
  • 123
  • 10
2
votes
1 answer

Add ONLY the total values on top of stacked bars

I am working with the following bar plot: And I would like to add only the total amount of each index on top of the bars, like this: However, when I use the following code, I only get parts of the stacks of each bar. import matplotlib.pyplot as…
2
votes
1 answer

How to annotate a gridded plot with values from a dict

I have this Matplotlib grid and would like to write text in each of the grid cells. The text is provided by a dictionary. How would I do this? Here's what I have so far: fig, ax = plt.subplots() plt.xlim(0, 3) plt.ylim(3,…
AI92
  • 387
  • 1
  • 8