Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
695 views
in Technique[技术] by (71.8m points)

matlab - X-axis label on two rows

str = {'HS31'; 'HS31 (Ridotto)';
    'Dax85';'Dax85 (Ridotto)';
    'FTSE89';'FTSE89 (Ridotto)';
    'SP98';'SP98 (Ridotto)';
    'Nikkei22';'Nikkei225 (Ridotto)';
    'SP457';'SP457 (Ridotto)';
    'Russ1318';'Russ1318 (Ridotto)';
    'Russ2151';'Russ2151 (Ridotto)';
    'Eurostoxx';'Eurostoxx (Ridotto)';
    'Ftse';'HS31 (Ridotto)';
    'Mibtel';'Mibtel (Ridotto)';
    'SP';'SP (Ridotto)';
    'Nasdaq';'Nasdaq (Ridotto)';

};
h=figure;
bar(t);
set(gca, 'XTickLabel',str, 'XTick',1:numel(str))

saveas(h, 'Backtesting/computing_time.png');

I can't read the text below the plot. Do you know how to fix it?

Screenshot: https://www.dropbox.com/s/g43iegh4oeng3kf/computing_time.png enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are okay with 90 degrees rotated text, you may try this code that is based on a very useful x-label rotating text tool, available here

Code

h=figure;
bar(randi(9,26,1),'EdgeColor','g') %// Assumed random data for demo
set(gca, 'XTickLabel',str, 'XTick',1:numel(str))
xticklabel_rotate([],90,str);%% File-exchange code %// xlabel text rotated
saveas(h, 'computing_time.png');

Sample plot with some random data

enter image description here

If you are okay with down-sampling the x-label text, i.e. for example show only every other label, use this right before creating the figure handle -

str(1:2:end)={[]}

Rest of the code stays the same. The output plot would look like this -

enter image description here

If you still want to keep the data horizontal, you need to downsample the number of labels by a good factor. In your given sample case, a factor of 4 worked. The changes in the code is adding the following code right after declaring str and of course commenting the x-label rotating tool usage -

str1 = cell(1,numel(str));
str1(1:4:end) = str(1:4:end);
str = str1;

The trick here is to use empty cells for the x-labels that you want to skip.

Result -

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...