Plots, Legends - Version compatibility issues in R2014b

2 views (last 30 days)
I am struggling to use some code for producing graphics written by someone else in an earlier version (around 2013), in particular with changes to the legend properties. Basically, the code works like this:
% Create handle:
legend1 = legend(area1,legendnames);
% Set properties:
set(legend1,'YColor',[1 1 1]);
set(legend1,'XColor',[1 1 1]);
set(legend1,'PlotBoxAspectRatio',[1 4 1]);
All of these calls to the set method now produce errors like this one:
Error using matlab.graphics.illustration.Legend/set
There is no YColor property on the Legend class.
I am working on R2014b (in a W7 Enterprise SP1 environement) and I am aware that there were some major graphics changes in R2014b . I went through the extensive documentation on these changes, however, I could not find the legend properties used above in the list of properties and syntaxes being removed or changed. So basically, my question is how do I get the code working again like it used to?
Another issue is that the code I am using was carefully designed to take care of axes ticks and labellings to make sure that all the text is properly legible, which worked fine previously. However, if I run the same code now (except for the few legend properties above there are no errors), then the resulting axis labels are all overlapping and illegible. So I wanted to know if there were any changes to the XTick, XTickLabel, FontSize properties that could explain this? The more fundamental question I am currently wrestling with is whether I should still use the old graphics functions at all. They are quite lengthy and were intended to be used as stable black-box solutions, so if I have to make too many changes now then it’s probably faster to just find a different solution.
  1 Comment
Brendan Hamm
Brendan Hamm on 26 Feb 2015
Regarding the legend properties which don't exist, these are all properties of the axes and not the legend. If this is indeed your error you can set the properties using gca, which gets the current axes.
set(gca,'YColor',[1 1 1]);
set(gca,'XColor',[1 1 1]);
set(gca,'PlotBoxAspectRatio',[1 4 1]);
It is a good idea to just create the axes explicitly before making the plot.
figure;
a = axes();
plot(...);
set(a,'YColor',[1 1 1]);
...
In terms of the axes properties for the tick labels, you can now rotate the tick labels. Check out the documentation for axes()
docsearch axes properties
Scroll down to "XTickLabelRotation, YTickLabelRotation, ZTickLabelRotation" located just beneath the LaTeX section. These will not be backward compatible though.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!