Issue with sgtitle and subplots. and question about applying a gradient hue to a lineplot

Hi folks,
I have the following code with an issue.
The sgtitle seems to appear in the output window but when the figure is opened in its own window, the title disappears!
Also, is it possible to apply a gradient hue to each line depending on another variable (temperature)?
Is there a way around this? My code is as follows:
for i = 1
figure;
myTitle = sprintf('VRA Parameters versus %s', myIDData{i});
sgtitle(myTitle);
for j = 1:14
subplot(7, 2, j);
plot(myData{i}, myData{j});
xlabel(myIDData{i}, "FontWeight","bold");
ylabel(myIDData{j}, "FontWeight","bold");
set(gca, 'xdir', 'reverse');
xlim([0 100]);
end
end

 Risposta accettata

It may be cut off because of the limits on the figure 'Position' or 'OuterPosition' property.
See if something like:
Fig = gcf;
pos = Fig.OuterPosition
Fig.OuterPosition = pos + [0 -200 0 200];
shifting it down by 200 and then increasing its height by 200 solves the problem.
figure
plot(1:10, randn(1,10))
grid
title('Title')
figure
plot(1:10, randn(1,10))
grid
title('Title')
Fig = gcf;
pos = Fig.OuterPosition;
Fig.OuterPosition = pos + [0 -200 0 200];
See the figure documentation on Position and Size for more information and other options to experiment with.
EDIT — (20 Sep 2022 at 15:40)
I am not certain about the gradient hue. See the patch documentation section on Create Multicolored Line for one approach.
.

12 Commenti

@Star Strider hi, unfortunately this doesn't seem to fix the issue with the title...I'm not entirely sure what else can be done!
I do not have your data, so I cannot reproduce the problem. There are other position and size properties that could work.
The multi-coloured line could still be an option.
If none of these work, I will delete my Answer in a few hours.
@Star Strider thanks, I have attached the variables so hopefully this can help get to the bottom of it!
Do you want the whole line to have one single color that depends on some other value, or do you want the color of the line to change as it goes from left to right?
@Image Analyst sorry if didn't make this clear! I want the line to have a gradient based on a third variable. I posted another question specific to this problem to hopefully make things clearer!
I am not certain how you are saving it and then loading it, since those details are missing.
It seems to work correctly here:
LD1 = load(websave('myData','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1130780/myData.mat'));
myData = LD1.myData;
LD2 = load(websave('myID','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1130785/myID.mat'));
myIDData = LD2.myIDData;
for i = 1
figure;
myTitle = sprintf('VRA Parameters versus %s', myIDData{i});
sgtitle(myTitle);
for j = 1:14
subplot(7, 2, j);
plot(myData{i}, myData{j});
xlabel(myIDData{i}, "FontWeight","bold");
ylabel(myIDData{j}, "FontWeight","bold", 'FontSize',6);
set(gca, 'xdir', 'reverse');
xlim([0 100]);
end
end
Fig = gcf;
pos = Fig.OuterPosition;
Fig.OuterPosition = pos + [0 -800 0 800]; % Resize (Different Parameters From Original)
saveas(gcf, 'Test20221920','png') % Write Figure As '.png' File
I2 = imread('Test20221920.png'); % Import Figure & Display
figure
image(I2)
Ax = gca;
Ax.XColor = 'none';
Ax.YColor = 'none';
Fig = gcf;
pos = Fig.OuterPosition;
Fig.OuterPosition = pos + [0 -800 0 800]; % Resize To Match Original
I reduced the ylabel font size to keep them from running into each other. The code is otherwise unchanged.
I am not certain what you want to do with the line colours, so I will leave that for the time being. The patch link I posted earlier should do what you want.
.
@Star Strider hi, I've tried this but unfortunately it only resizes one subplot! I'm not sure where the error is...I've tried changing the number of plots in the rows and columns of subplot and have it with and without the second y axis. Still no dice!
for i = 1
figure;
myTitle = sprintf('VRA Parameters versus %s', myIDData{i});
sgtitle(myTitle);
for j = 1:14
subplot(5, 3, j);
yyaxis left;
p = plot(myData{i}, myData{j});
xlabel(myIDData{i}, "FontWeight","bold");
ylabel(myIDData{j}, "FontWeight","bold", 'FontSize',6);
yyaxis right;
p = plot(myData{i}, myGradData{j});
ylabel(["\Delta", myIDData{j}], "FontWeight", "bold");
set(gca, 'xdir', 'reverse');
end
end
saveas(gcf, 'Test','png');
Fig = gcf;
Fig.OuterPosition = Fig.OuterPosition + [0 -800 0 800];
I don’t have ‘myGradData’ so I can’t run it. The saveas call has to go after the figure is resized.
LD1 = load(websave('myData','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1130780/myData.mat'));
myData = LD1.myData;
LD2 = load(websave('myID','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1130785/myID.mat'));
myIDData = LD2.myIDData;
for i = 1
figure;
myTitle = sprintf('VRA Parameters versus %s', myIDData{i});
sgtitle(myTitle);
for j = 1:14
subplot(5, 3, j);
yyaxis left;
p = plot(myData{i}, myData{j});
xlabel(myIDData{i}, "FontWeight","bold");
ylabel(myIDData{j}, "FontWeight","bold", 'FontSize',6);
yyaxis right;
p = plot(myData{i}, myGradData{j});
ylabel(["\Delta", myIDData{j}], "FontWeight", "bold");
set(gca, 'xdir', 'reverse');
end
end
Undefined variable 'myGradData'.
Fig = gcf;
Fig.OuterPosition = Fig.OuterPosition + [0 -800 0 800];
saveas(gcf, 'Test','png');
.
@Star Strider hi, I've tried this but I get the following result in full screen mode:
My approach works for me.
I do not have all your data or apparently enough of your code to reproduce the problem, so I cannot run your code to see what the problem is.
I doubt that this could be a graphics driver or renderer problem, however it would be best for you to be certain the drivers are up-to-date. Use the rendererinfo function to determine that. The opengl function will be removed, however it now still exists, so experimenting with it could be an option as well.
Example —
ri = rendererinfo
ri = struct with fields:
GraphicsRenderer: 'OpenGL Software' Vendor: 'Brian Paul' Version: '2.1 Mesa 17.1.3' RendererDevice: 'Mesa X11' Details: [1×1 struct]
ri.Details
ans = struct with fields:
HardwareSupportLevel: 'None' SupportsDepthPeelTransparency: 1 SupportsAlignVertexCenters: 0 SupportsGraphicsSmoothing: 0 MaxTextureSize: 16384 MaxFrameBufferSize: 16384
opengl info
Version: '2.1 Mesa 17.1.3' Vendor: 'Brian Paul' Renderer: 'Mesa X11' MaxTextureSize: 16384 Visual: 'Visual 0x41, (RGBA 32 bits (8 8 8 8), Z depth 16 bits, Hardware acceleration, Double buffer, Antialias 0 samples)' Software: 'true' HardwareSupportLevel: 'none' SupportsGraphicsSmoothing: 0 SupportsDepthPeelTransparency: 1 SupportsAlignVertexCenters: 0 Extensions: {152×1 cell} MaxFrameBufferSize: 16384
.
@Star Strider apologies, I restarted matlab and it seems to work now! I'm not sure what the issue was but it seems to have been resolved!

Accedi per commentare.

Più risposte (0)

Prodotti

Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by