2010-08-31 13 views
15

जो मैं चाहता हूं वह वास्तव में सरल है। मेरे पास "logo.png" नामक एक छोटी छवि फ़ाइल है जिसे मैं अपने भूखंडों के ऊपरी बाएं कोने पर प्रदर्शित करना चाहता हूं। लेकिन तुम नहीं कर सकते कि matplotlibmatplotlib के साथ एक साजिश के कोने पर एक छोटी छवि कैसे सम्मिलित करें?

इम Django का उपयोग कर, के उदाहरण गैलरी में से किसी उदाहरण खोजने के लिए और मेरे कोड इस

def get_bars(request) 
    ... 
    fig = Figure(facecolor='#F0F0F0',figsize=(4.6,4)) 
    ... 
    ax1 = fig.add_subplot(111,ylabel="Valeur",xlabel="Code",autoscale_on=True) 
    ax1.bar(ind,values,width=width, color='#FFCC00',edgecolor='#B33600',linewidth=1) 
    ... 
    canvas = FigureCanvas(fig) 
    response = HttpResponse(content_type='image/png') 
    canvas.print_png(response) 
    return response 

किसी भी विचार की तरह कुछ है ?? अग्रिम में thxs

उत्तर

25

यदि आप अपनी वास्तविक आकृति के कोने पर छवि चाहते हैं (अपनी धुरी के कोने के बजाए), figimage देखें।

शायद ऐसा कुछ? एक अन्य विकल्प है, अगर आप छवि आंकड़ा की चौड़ाई/ऊंचाई की एक निश्चित अंश हो करना चाहते हैं है एक "डमी" बनाने के लिए

import matplotlib.pyplot as plt 
import Image 
import numpy as np 

im = Image.open('/home/jofer/logo.png') 
height = im.size[1] 

# We need a float array between 0-1, rather than 
# a uint8 array between 0-255 
im = np.array(im).astype(np.float)/255 

fig = plt.figure() 

plt.plot(np.arange(10), 4 * np.arange(10)) 

# With newer (1.0) versions of matplotlib, you can 
# use the "zorder" kwarg to make the image overlay 
# the plot, rather than hide behind it... (e.g. zorder=10) 
fig.figimage(im, 0, fig.bbox.ymax - height) 

# (Saving with the same dpi as the screen default to 
# avoid displacing the logo image) 
fig.savefig('/home/jofer/temp.png', dpi=80) 

plt.show() 

alt text

: (जनहित याचिका का उपयोग कर छवि को पढ़ने के लिए) अक्षों और छवि को imshow के साथ रखें। इस तरह से छवि के आकार और स्थिति डीपीआई से स्वतंत्र है और यह आंकड़ा के पूर्ण आकार:

import matplotlib.pyplot as plt 
from matplotlib.cbook import get_sample_data 

im = plt.imread(get_sample_data('grace_hopper.jpg')) 

fig, ax = plt.subplots() 
ax.plot(range(10)) 

# Place the image in the upper-right corner of the figure 
#-------------------------------------------------------- 
# We're specifying the position and size in _figure_ coordinates, so the image 
# will shrink/grow as the figure is resized. Remove "zorder=-1" to place the 
# image in front of the axes. 
newax = fig.add_axes([0.8, 0.8, 0.2, 0.2], anchor='NE', zorder=-1) 
newax.imshow(im) 
newax.axis('off') 

plt.show() 

enter image description here

+0

यह काम किया ... एक बहुत thxs! – pleasedontbelong

+0

क्या इस लोगो को निचले दाएं से संबंधित स्थिति में रखने का कोई तरीका है? – Jared

+0

@ जेरेड - कुछ के साथ कुछ कोशिश करें: 'fig.figimage (im, fig.bbox.xmax - चौड़ाई, ऊंचाई)' –

संबंधित मुद्दे