Tengo un diagrama que tiene marcas de tiempo en el eje xy algunos datos de señal en el eje y. Como documentación, quiero poner las marcas de tiempo en relación con puntos específicos de la trama. ¿Es posible trazar una línea en un diagrama de una imagen en una secuencia de imágenes debajo de la trama?Combinar imagen y trazar con Python Matplotlib
14
A
Respuesta
16
This demo de la galería de matplotlib muestra cómo insertar imágenes, dibujar líneas, etc. Publicaré la imagen de la galería, y puede seguir el link para ver el código.
Y aquí está el código (de la versión 2.1.2):
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Circle
from matplotlib.offsetbox import (TextArea, DrawingArea, OffsetImage,
AnnotationBbox)
from matplotlib.cbook import get_sample_data
if 1:
fig, ax = plt.subplots()
# Define a 1st position to annotate (display it with a marker)
xy = (0.5, 0.7)
ax.plot(xy[0], xy[1], ".r")
# Annotate the 1st position with a text box ('Test 1')
offsetbox = TextArea("Test 1", minimumdescent=False)
ab = AnnotationBbox(offsetbox, xy,
xybox=(-20, 40),
xycoords='data',
boxcoords="offset points",
arrowprops=dict(arrowstyle="->"))
ax.add_artist(ab)
# Annotate the 1st position with another text box ('Test')
offsetbox = TextArea("Test", minimumdescent=False)
ab = AnnotationBbox(offsetbox, xy,
xybox=(1.02, xy[1]),
xycoords='data',
boxcoords=("axes fraction", "data"),
box_alignment=(0., 0.5),
arrowprops=dict(arrowstyle="->"))
ax.add_artist(ab)
# Define a 2nd position to annotate (don't display with a marker this time)
xy = [0.3, 0.55]
# Annotate the 2nd position with a circle patch
da = DrawingArea(20, 20, 0, 0)
p = Circle((10, 10), 10)
da.add_artist(p)
ab = AnnotationBbox(da, xy,
xybox=(1.02, xy[1]),
xycoords='data',
boxcoords=("axes fraction", "data"),
box_alignment=(0., 0.5),
arrowprops=dict(arrowstyle="->"))
ax.add_artist(ab)
# Annotate the 2nd position with an image (a generated array of pixels)
arr = np.arange(100).reshape((10, 10))
im = OffsetImage(arr, zoom=2)
im.image.axes = ax
ab = AnnotationBbox(im, xy,
xybox=(-50., 50.),
xycoords='data',
boxcoords="offset points",
pad=0.3,
arrowprops=dict(arrowstyle="->"))
ax.add_artist(ab)
# Annotate the 2nd position with another image (a Grace Hopper portrait)
fn = get_sample_data("grace_hopper.png", asfileobj=False)
arr_img = plt.imread(fn, format='png')
imagebox = OffsetImage(arr_img, zoom=0.2)
imagebox.image.axes = ax
ab = AnnotationBbox(imagebox, xy,
xybox=(120., -80.),
xycoords='data',
boxcoords="offset points",
pad=0.5,
arrowprops=dict(
arrowstyle="->",
connectionstyle="angle,angleA=0,angleB=90,rad=3")
)
ax.add_artist(ab)
# Fix the display limits to see everything
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
plt.show()
14
Si entiendo bien la pregunta, entonces tal vez esto puede ayudar:
import scipy
import pylab
fig = pylab.figure()
axplot = fig.add_axes([0.07,0.25,0.90,0.70])
axplot.plot(scipy.randn(100))
numicons = 8
for k in range(numicons):
axicon = fig.add_axes([0.07+0.11*k,0.05,0.1,0.1])
axicon.imshow(scipy.rand(4,4),interpolation='nearest')
axicon.set_xticks([])
axicon.set_yticks([])
fig.show()
fig.savefig('iconsbelow.png')
+0
Cuando los bordes negros alrededor de las imágenes no son deseables, los comandos 'axicon.set_xticks ([])' y 'axicon.set_yticks ([])' puede ser reemplazado por 'axicon.axis ('off')'. –
Cuestiones relacionadas
- 1. ¿Es posible trazar una imagen en un mapa con matplotlib?
- 2. Trazar comportamientos propios con matplotlib
- 3. Cómo trazar cdf en matplotlib en Python?
- 4. Trazar los ejes logarítmicos con matplotlib en python
- 5. Cómo trazar una imagen con un eje y no lineal con Matplotlib usando imshow?
- 6. Cómo trazar vectores matemáticos 2D con matplotlib?
- 7. Cómo trazar pldf empírico en matplotlib en Python?
- 8. Python: cómo trazar gráficos en 3D con Python?
- 9. Trazar Elipse con matplotlib.pyplot (Python)
- 10. ¿Cómo acelerar el matplotlib al trazar y guardar muchas figuras?
- 11. ¿Es posible trazar ecuaciones implícitas usando Matplotlib?
- 12. matplotlib, puede trazar pero no dispersar
- 13. Trazar las fechas en el eje x con matplotlib de Python
- 14. python y actualizar figura en matplotlib
- 15. Cómo trazar una línea de color de degradado en matplotlib?
- 16. Trazar un gráfico acumulativo de python datetimes
- 17. Nuevo en Python ... Python 3 y Matplotlib
- 18. matplotlib gráfico imagen pequeña sin remuestreo
- 19. Python y Matplotlib y anotaciones con Mouse Hover
- 20. Combinar imagen y texto para dibujar
- 21. Trazar histograma en Python
- 22. imagen Matplotlib savefig recortar
- 23. Cómo trazar una colección de parches 3D en matplotlib?
- 24. Matplotlib para Python 3 y Linux
- 25. Cómo trazar un gráfico de barras muy simple (Python, Matplotlib) usando el archivo de entrada * .txt?
- 26. Python: Matplotlib anota salto de línea (con y sin látex)
- 27. Matplotlib en Python - Dibujando formas y animándolas
- 28. Python con matplotlib - reutilizando funciones de dibujo
- 29. Conteo rectangular de Python Matplotlib
- 30. ¿Cómo puedo trazar los valores NaN como un color especial con imshow en matplotlib?
¿El Alguien sabe si esto funciona en 3D? podemos agregar una imagen a un avión? – CromeX
@CromeX: por favor haga una pregunta por separado. Los enlaces – tom10
ya no parecen funcionar. –