imshow

how do I redraw an image using python's matplotlib?

北慕城南 提交于 2019-11-29 18:16:31
问题 What I am trying to do seems to be fairly straightforward, but I'm having a heck of a time trying to get it to work. I am simply trying to draw an image using imshow and then re-draw it periodically as new data arrives. I've started out with this: fig = figure() ax = plt.axes(xlim=(0,200),ylim=(0,200)) myimg = ax.imshow(zeros((200,200),float)) Then I'm assuming I can call set_data like this to update the image: myimg.set_data(newdata) I've tried many other things, for example I've called ax

matplotlib 2D plot from x,y,z values

不想你离开。 提交于 2019-11-29 15:32:38
I am a Python beginner. I have a list of X values x_list = [-1,2,10,3] and I have a list of Y values y_list = [3,-3,4,7] I then have a Z value for each couple. Schematically, this works like that: X Y Z -1 3 5 2 -3 1 10 4 2.5 3 7 4.5 and the Z values are stored in z_list = [5,1,2.5,4.5] . I need to get a 2D plot with the X values on the X axis, the Y values on the Y axis, and for each couple the Z value, represented by an intensity map. This is what I have tried, unsuccessfully: X, Y = np.meshgrid(x_list, y_list) fig, ax = plt.subplots() extent = [x_list.min(), x_list.max(), y_list.min(), y

cv::imshow sometimes is very slow

一笑奈何 提交于 2019-11-29 14:32:41
问题 I've got a problem with cv::imshow . It normally consumes about 1-2 ms processing time for my image size but at some point in my processing-pipeline it uses 4-8 ms for the same kind of images. I have a method void Tool::displayImage() { startTimeMeasure(); cv::imshow("output",image); evaluateTimeMeasure(); } image is a member variable and the highgui window is created somewhere else. Time measurement works with boost::posix_time ptime and time_duration . cvStartWindowThread(); was called. The

Opencv imshow() freezes when updating

瘦欲@ 提交于 2019-11-29 08:20:36
问题 For my image processing algorithm I'm using python / OpenCV. The output of my algorithm shall be updated im the same window over and over again. However sometimes the window freezes and doesn't update at all, but the algorithm is still running and updated the picture a multiple times in the meantime. The window turns dark gray on this Ubuntu machine. Here is an excerpt of the involved code: for i in range(0,1000): img = loadNextImg() procImg = processImg(img) cv2.imshow("The result", procImg)

How to add legend to imshow() in matplotlib

荒凉一梦 提交于 2019-11-29 07:12:29
I am using matplotlib In plot() or bar() , we can easily put legend, if we add labels to them. but what if it is a contourf() or imshow() I know there is a colorbar() which can present the color range, but it is not satisfied. I want such a legend which have names(labels). For what I can think of is that, add labels to each element in the matrix, then ,try legend(), to see if it works, but how to add label to the element, like a value?? in my case, the raw data is like: 1,2,3,3,4 2,3,4,4,5 1,1,1,2,2 for example, 1 represents 'grass', 2 represents 'sand', 3 represents 'hill'... and so on.

OpenCV & Python - Image too big to display

旧巷老猫 提交于 2019-11-29 02:56:10
I have an image that is 6400 × 3200, while my screen is 1280 x 800. Therefore, the image needs to be resized for display only. I am using Python and OpenCV 2.4.9. According to OpenCV Documentation , If you need to show an image that is bigger than the screen resolution, you will need to call namedWindow("", WINDOW_NORMAL) before the imshow. That is what I am doing, but the image is not fitted to the screen, only a portion is shown because it's too big. I've also tried with cv2.resizeWindow, but it doesn't make any difference. import cv2 cv2.namedWindow("output", cv2.WINDOW_NORMAL) # Create

Two different color colormaps in the same imshow matplotlib

可紊 提交于 2019-11-29 01:40:28
Let's suppose the example below import matplotlib.pyplot as plt import numpy as np v1 = -1 + 2*np.random.rand(50,150) fig = plt.figure() ax = fig.add_subplot(111) p = ax.imshow(v1,interpolation='nearest') cb = plt.colorbar(p,shrink=0.5) plt.xlabel('Day') plt.ylabel('Depth') cb.set_label('RWU') plt.show() I want to show the values below zero in a different colormap than the values above zero First of all, is it possible that you just want to use a diverging colormap, 'neutral' at zero, and diverging to two distinct colours? This is an example: import matplotlib.pyplot as plt import numpy as np

Dates in the xaxis for a matplotlib plot with imshow

柔情痞子 提交于 2019-11-29 01:25:49
So I am new to programming with matplotlib. I have created a color plot using imshow() and an array. At first the axis were just the row and column number of my array. I used extent = (xmin,xmax,ymin,ymax) to get the x-axis in unix time and altitude, respectively. I want to change the x-axis from unix time (982376726,982377321) to UT(02:25:26, 02:35:21). I have created a list of the time range in HH:MM:SS. I am not sure how to replace my current x-axis with these new numbers, without changing the color plot (or making it disappear). I was looking at datetime.time but I got confused with it.

Adjusting gridlines and ticks in matplotlib imshow

守給你的承諾、 提交于 2019-11-29 00:43:08
问题 I'm trying to plot a matrix of values and would like to add gridlines to make the boundary between values clearer. Unfortunately, imshow decided to locate the tick marks in the middle of each voxel. Is it possible to a) remove the ticks but leave the label in the same location and b) add gridlines between the pixel boundaries? import matplotlib.pyplot as plt import numpy as np im = plt.imshow(np.reshape(np.random.rand(100), newshape=(10,10)), interpolation='none', vmin=0, vmax=1, aspect=

Contour/imshow plot for irregular X Y Z data

对着背影说爱祢 提交于 2019-11-28 19:23:57
I have data in X, Y, Z format where all are 1D arrays, and Z is the amplitude of the measurement at coordinate (X,Y). I'd like to show this data as a contour or 'imshow' plot where the contours/color represent the the value Z (amplitude). The grid for measurements and X and Y look are irregularly spaced. Many thanks, len(X)=100 len(Y)=100 len(Z)=100 Does plt.tricontourf(x,y,z) satisfy your requirements? It will plot filled contours for irregularly spaced data (non-rectilinear grid). You might also want to look into plt.tripcolor() . import numpy as np import matplotlib.pyplot as plt x = np