[PYTHON] Python Matplotlib로 그림과 그림 결합
PYTHONPython Matplotlib로 그림과 그림 결합
나는 x 축에 타임 스탬프가 있고 y 축에 일부 신호 데이터가있는 그림이 있습니다. 문서화로서, 플롯의 특정 포인트와 관련하여 타임 스탬프 된 그림을 넣고 싶습니다. 플롯 아래 그림의 순서로 그림에 선을 그릴 수 있습니까?
해결법
-
==============================
1.matplotlib 갤러리의이 데모에서는 사진을 삽입하고 선을 그리는 방법 등을 보여줍니다. 갤러리에서 이미지를 게시하고 링크를 따라 코드를 볼 수 있습니다.
matplotlib 갤러리의이 데모에서는 사진을 삽입하고 선을 그리는 방법 등을 보여줍니다. 갤러리에서 이미지를 게시하고 링크를 따라 코드를 볼 수 있습니다.
다음은 버전 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()
-
==============================
2.질문을 올바르게 이해하면 아마도 도움이 될 것입니다.
질문을 올바르게 이해하면 아마도 도움이 될 것입니다.
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')
from https://stackoverflow.com/questions/3765056/combine-picture-and-plot-with-python-matplotlib by cc-by-sa and MIT license
'PYTHON' 카테고리의 다른 글
[PYTHON] "% s"% 형식과 "{0}". format () vs "?"형식 (0) | 2018.11.02 |
---|---|
[PYTHON] X에서 활성 창 제목 가져 오기 (0) | 2018.11.02 |
[PYTHON] 로컬 컴퓨터 또는 웹 리소스에서 jupyter 노트북에 이미지 또는 그림을 포함시키는 방법? (0) | 2018.11.02 |
[PYTHON] 헤 루쿠 산발적 인 높은 응답 시간 (0) | 2018.11.02 |
[PYTHON] Python : PIL은 단일 RGBA 색상을 대체합니다. (0) | 2018.11.02 |