How to surround curves with annotation in matplotlib?

Jika

I have a python code that produces the following figures. I would like to do an annotation with ellipses to surround the curves as the figure mentions.

enter image description here

N.B. The figure is produced using MATLAB and I cannot do it in python-matplotlib. Thanks.

xnx

You could try the following to position your ellipses: choose an x-coordinate and calculate the height of the ellipse necessary to enclose the provided list of functions at that coordinate.

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Ellipse

x = np.linspace(1,10,1000)

flogs = [lambda x, a=a: np.log(a * x) for a in range(1,4)]
fexps = [lambda x, a=a: np.exp(a * x) for a in [0.18,0.2]]
funcs = flogs + fexps

fig = plt.figure()
ax = fig.add_subplot(111)

for func in funcs:
    ax.plot(x,func(x))


def add_ellipse(funcs, x):
    # the y-coordinate of the center of our ellipse:
    y = np.mean([funcs[i](x) for i in range(len(funcs))])
    # fix the width of the ellipse to this value:
    w = 0.4
    # find the height of the ellipse needed, and pad a bit:
    h = np.ptp([funcs[i](x) for i in range(len(funcs))]) * 1.5
    e = Ellipse(xy=(x,y), width=w, height=h, angle=0)
    e.set_facecolor('none')
    ax.add_artist(e)

add_ellipse(fexps, 8.5)
add_ellipse(flogs, 8)

plt.show()

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to change color of plotted curves when using Animations in Python MatPlotLib?

From Dev

Python -- matplotlib elliptic curves

From Java

How to surround text with spaces?

From Dev

How to rotate matplotlib annotation to match a line?

From Dev

How do I put a circle with annotation in matplotlib?

From Dev

How to rotate matplotlib annotation to match a line?

From Dev

How to prevent Matplotlib annotation out of the frame of the plot

From Dev

Making Load Duration Curves in Matplotlib

From Dev

Making Load Duration Curves in Matplotlib

From Dev

Plotting Treasury Yield Curve, how to overlay two yield curves using matplotlib

From Java

how to represent data in a graph using matplotlib plt.plot(df) by smoothening the curves?

From Java

How to surround flutter widget in vscode

From Dev

How to surround arrays with one array?

From Dev

How to surround a form with an opaque background?

From Dev

How to extrapolate curves in Python?

From Dev

Output matplotlib figure to SVG with text as text, not curves

From Dev

Matplotlib: Argument dimensions are incompatible fill between curves

From Dev

Error bars in matplotlib display over other curves

From Dev

Plot multiple curves with matplotlib.pyplot.fill

From Dev

How to plot numbers from an array as annotation using matplotlib?

From Dev

Matplotlib, how to write annotation outside the drawing in data coords?

From Dev

Matplotlib annotation detailed documentation

From Dev

Annotation along a curve in matplotlib

From Dev

matplotlib multiple line annotation

From Dev

Matplotlib Annotation not working

From Dev

matplotlib text annotation horizontal

From Dev

Annotation along a curve in matplotlib

From Dev

Update a specific annotation in matplotlib

From Dev

In IntelliJ IDEA, how to surround with try-with-resources?

Related Related

  1. 1

    How to change color of plotted curves when using Animations in Python MatPlotLib?

  2. 2

    Python -- matplotlib elliptic curves

  3. 3

    How to surround text with spaces?

  4. 4

    How to rotate matplotlib annotation to match a line?

  5. 5

    How do I put a circle with annotation in matplotlib?

  6. 6

    How to rotate matplotlib annotation to match a line?

  7. 7

    How to prevent Matplotlib annotation out of the frame of the plot

  8. 8

    Making Load Duration Curves in Matplotlib

  9. 9

    Making Load Duration Curves in Matplotlib

  10. 10

    Plotting Treasury Yield Curve, how to overlay two yield curves using matplotlib

  11. 11

    how to represent data in a graph using matplotlib plt.plot(df) by smoothening the curves?

  12. 12

    How to surround flutter widget in vscode

  13. 13

    How to surround arrays with one array?

  14. 14

    How to surround a form with an opaque background?

  15. 15

    How to extrapolate curves in Python?

  16. 16

    Output matplotlib figure to SVG with text as text, not curves

  17. 17

    Matplotlib: Argument dimensions are incompatible fill between curves

  18. 18

    Error bars in matplotlib display over other curves

  19. 19

    Plot multiple curves with matplotlib.pyplot.fill

  20. 20

    How to plot numbers from an array as annotation using matplotlib?

  21. 21

    Matplotlib, how to write annotation outside the drawing in data coords?

  22. 22

    Matplotlib annotation detailed documentation

  23. 23

    Annotation along a curve in matplotlib

  24. 24

    matplotlib multiple line annotation

  25. 25

    Matplotlib Annotation not working

  26. 26

    matplotlib text annotation horizontal

  27. 27

    Annotation along a curve in matplotlib

  28. 28

    Update a specific annotation in matplotlib

  29. 29

    In IntelliJ IDEA, how to surround with try-with-resources?

HotTag

Archive