MATLAB Answers

How to subplot figures reopened from .fig files correctly when they containing images?

1 view (last 30 days)
Zsolt Kocsis
Zsolt Kocsis on 6 Oct 2020
I have some saved figures, mostly containing images (imshow) and lines plotted to them. I would like to display them in a subplot after opening them again.
I was trying the copyobj-related suggestions here in the forum, but they don't work well in this situation. The problems are:
  • Images are displayed upside down
  • The out-of-image parts of the lines appearing in the subplot
  • Aspect ratio changes
When I just reopen the .fig files and display them individually as separate figures there is no problem, it displays well.
Could anybody help me, how to display the subplots to look like the original figures?

Answers (1)

Constantino Carlos Reyes-Aldasoro
What you have to do is to grab each element by its handles, to grab the handles of a figure you use
>> h0=gcf;
then you can access the fields, i.e.
>> get(h0)
Alphamap: [1×64 double]
BeingDeleted: 'off'
BusyAction: 'queue'
ButtonDownFcn: ''
Children: [1×1 Axes]
Clipping: 'on'
CloseRequestFcn: 'closereq'
Color: [0.9400 0.9400 0.9400]
Colormap: [64×3 double]
CreateFcn: ''
CurrentAxes: [1×1 Axes]
CurrentCharacter: ''
CurrentObject: [0×0 GraphicsPlaceholder]
CurrentPoint: [0 0]
DeleteFcn: ''
DockControls: 'on'
FileName: 'C:\Users\sbbk034\Desktop\derivative.png'
GraphicsSmoothing: 'on'
HandleVisibility: 'on'
InnerPosition: [960 230 560 420]
IntegerHandle: 'on'
Interruptible: 'on'
InvertHardcopy: 'on'
KeyPressFcn: ''
KeyReleaseFcn: ''
MenuBar: 'figure'
Name: ''
NextPlot: 'add'
Number: 1
NumberTitle: 'on'
OuterPosition: [952 222 576 513]
PaperOrientation: 'portrait'
PaperPosition: [3.0917 9.2937 14.8167 11.1125]
PaperPositionMode: 'auto'
PaperSize: [21.0000 29.7000]
PaperType: 'A4'
PaperUnits: 'centimeters'
Parent: [1×1 Root]
Pointer: 'arrow'
PointerShapeCData: [16×16 double]
PointerShapeHotSpot: [1 1]
Position: [960 230 560 420]
Renderer: 'opengl'
RendererMode: 'auto'
Resize: 'on'
Scrollable: 'off'
SelectionType: 'normal'
SizeChangedFcn: ''
Tag: ''
ToolBar: 'auto'
Type: 'figure'
UIContextMenu: [0×0 GraphicsPlaceholder]
Units: 'pixels'
UserData: []
Visible: 'on'
WindowButtonDownFcn: ''
WindowButtonMotionFcn: ''
WindowButtonUpFcn: ''
WindowKeyPressFcn: ''
WindowKeyReleaseFcn: ''
WindowScrollWheelFcn: ''
WindowState: 'normal'
WindowStyle: 'normal'
>>
In this case I had one subplot so the children is just one axes, but if it were more, it would show, you can then grab the handles of the children like this
>> h1=h0.Children
h1 =
Axes with properties:
XLim: [0 0.0600]
YLim: [0 0.1000]
XScale: 'linear'
YScale: 'linear'
GridLineStyle: '-'
Position: [0.1300 0.1100 0.7750 0.8150]
Units: 'normalized'
Show all properties
>>
And now h1 can be used to manipulate that axis, look at the position. If you had more children then you can grab each and manipulate as necessary.
Hope this answers your problem.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by