getframe captures only a corner of the axes
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am running the following code to try to capture an axis, as shown in the leftmost attached image.
figure;
plot(1:10, 1:10);
frame = getframe;
figure;
imagesc(frame.cdata)
The output of the above code is in the second attached image. As you can see, it results in an inexplicably cropped version of the axes, where only the bottom left corner of the axes is captured. I tried playing with the figure and axis position, as well as different settings of the axis ("tight," "off," etc.) but to no avail. The same thing happens with getframe(gca), so specifying the axis does not help. I also tried playing with getframe(gca, Rect) -- for example, I do getframe(gca, getpixelposition(gca)), but I got an error that the rectangle doesn't fit within the figure.
If I use getframe(gcf), that doesn't happen, but capturing the whole figure adds some extra whitespace even when I do "axis off", as can be seen in the last attached image, where I have plotted the resulting frame.cdata with imagesc. I don't want that deadspace. I want to capture the axis exactly as it is, no more, no less. In addition, I don't want to use exportgraphics or anything else. I want the underlying pixel values as an array.
Finally, I tried using the print function, but that didn't work either. It has the same sort of issues as explained in the previous paragraph with adding whitespace to the captured figure.



1 Commento
Walter Roberson
il 6 Ago 2025
I wonder if it is due to a known bug, described at https://www.mathworks.com/matlabcentral/answers/2177698-strange-behaviour-of-plot#answer_1566533
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Printing and Saving in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!