Hi,
Does anyone can help me figure out why my colorbar title is always partly outside of the axis?
Below is my code:
scatter(app.ViewDEM,X_1,Y_1,200,Z_1,'s','filled')
colormap(app.ViewDEM)
d = colorbar(app.ViewDEM);
d.Label.String = 'Elevation [m]';
Thank you very much!

3 commentaires

Adam Danz
Adam Danz le 19 Juin 2019
Is this in app designer?
Adam Danz
Adam Danz le 19 Juin 2019
Modifié(e) : Adam Danz le 19 Juin 2019
I tried to recreate this problem by setting a UIAxes in App Designer very close to the right edge of the UI figure and then adding a colorbar to the right with a y axis label but the axes adjusts accordingly and I cannot recreate the problem.
Could you provide a bit more code? I'm curious if you're setting the axis position.
ZC Song
ZC Song le 20 Juin 2019
Yes, sometimes it works well. But in this case is not. Now I upload the data (X_1, Y_1, Z_1) and named the axis to 'app.UIAxes4'. The code is below:
scatter(app.UIAxes4,X_1,Y_1,200,Z_1,'s','filled')
colormap(app.UIAxes4)
d = colorbar(app.UIAxes4);
d.Label.String = 'Elevation [m]';
d.Label.FontSize = 10;
hold on

Connectez-vous pour commenter.

 Réponse acceptée

Adam Danz
Adam Danz le 20 Juin 2019
I was able to reproduce the problem after embedding the code you provided (copied below) within an app. It looks like a bug and should be reported. I thought of two workarounds listed below.
% Your example code that reproduces the problem
scatter(app.UIAxes4,X_1,Y_1,200,Z_1,'s','filled')
% colormap(app.UIAxes4) %Commented out; this just returns the current colormap
d = colorbar(app.UIAxes4);
d.Label.String = 'Elevation [m]';
d.Label.FontSize = 10;
hold on
% Workaround #1
% Move the colorbar y axis label to the left.
d.AxisLocation = 'in'
% Workaround #2
% Expand the width of the outer position of the axes a bit
% Look as your axes' current width value and chose a value slightly higher (+20 ?)
app.UIAxes.OuterPosition(3) = 500; % Change this value to fit your needs

3 commentaires

ZC Song
ZC Song le 20 Juin 2019
Yes I agree it seems like a bug because that code works well in regular matlab but app designer.
Workaround #1 and 2# could be alternatives. I have workaround #3 and making the title on the top of the colorbar:
set(get(d,'title'),'string','Elevation [m]', 'FontSize',10);
Anyway, thank you very much for following my question.
Nice teamwork!
A better way to set the title of the colorbar:
title(d, 'Elevation [m]', 'FontSize', 10)
ZC Song
ZC Song le 21 Juin 2019
Yes this one looks more concise!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Color and Styling dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by