2010-02-23 11 views

Respuesta

21

No creo que matplotlib pueda personalizar marcadores como ese. Consulte here para conocer el nivel de personalización, que es muy inferior a lo que necesita.

Como alternativa, he codificado este kludge que usa imágenes para colocar imágenes en las ubicaciones del punto de línea.

import matplotlib.pyplot as plt 
import matplotlib.image as image 

# constants 
dpi = 72; imageSize = (32,32) 
# read in our png file 
im = image.imread('smile.png') 

fig = plt.figure(dpi=dpi) 
ax = fig.add_subplot(111) 
# plot our line with transparent markers, and markersize the size of our image 
line, = ax.plot((1,2,3,4),(1,2,3,4),"bo",mfc="None",mec="None",markersize=imageSize[0] * (dpi/ 96)) 
# we need to make the frame transparent so the image can be seen 
# only in trunk can you put the image on top of the plot, see this link: 
# http://www.mail-archive.com/[email protected]/msg14534.html 
ax.get_frame().set_alpha(0) 
ax.set_xlim((0,5)) 
ax.set_ylim((0,5)) 

# translate point positions to pixel positions 
# figimage needs pixels not points 
line._transform_path() 
path, affine = line._transformed_path.get_transformed_points_and_affine() 
path = affine.transform_path(path) 
for pixelPoint in path.vertices: 
    # place image at point, centering it 
    fig.figimage(im,pixelPoint[0]-imageSize[0]/2,pixelPoint[1]-imageSize[1]/2,origin="upper") 

plt.show() 

alt text http://i50.tinypic.com/war39w.png

+2

AttributeError: objeto 'AxesSubplot' no tiene atributo 'get_frame' – erogol

+0

Véase la respuesta por t gillespie para manejar el error get_frame – Joel

5

A raíz de la respuesta de la marca. Solo pensé en agregar algo más porque intenté ejecutar esto y hago lo que quiero, a excepción de mostrar los íconos en el gráfico. Tal vez algo ha cambiado con matplotlib. Es tiene sido 4 años.

La línea de código que lee:

ax.get_frame().set_alpha(0) 

no parece funcionar, sin embargo

ax.patch.set_alpha(0) 

funciona.

+0

http://matplotlib.org/faq/howto_faq.html –

Cuestiones relacionadas