nice boxes for great linewidths

조회 수: 20 (최근 30일)
Clemens
Clemens 2011년 4월 14일
Hi,
I'm producing lots of boxplots for a collegue of mine. He needs them with a very big line width (for poster or so, and insists on png files). So I resize the lines after plotting (using findall). but after saving it ends up like: http://i51.tinypic.com/2n9ccpz.png
The corners aren't drawn properly. Funny thing is that on the screen 3 of the 4 corners are drawn nicely rounded.
I wonder if anyone has tips to make boxes properly.
Don't know if it matters but my workplace is still at 2009a.

채택된 답변

Clemens
Clemens 2011년 4월 15일
hmmm the boxes idea looks clear. Though I'm a bit anxious about it since it might have some side effects on the other graphics I have in the plot - notches eg. (which for reference looks like: http://i54.tinypic.com/k9hoom.png )
I think the problem lies with the ways lines are printed. Also a random line:
x = 1:10; y=rand(10,1);l= line(x,y,'LineWidth',32);
Thinking about this I came up with an idea. If I'd put dot markers on all corners it should cover the "shame". They'd just have to be the same size as the line. I'm just experimenting with that.
  댓글 수: 2
Clemens
Clemens 2011년 4월 15일
Lucky me. The first try looks good: http://i54.tinypic.com/bfq1q8.png
lineWidth = 16; lineCover=3*lineWidth;
a = [findall(gcf,'Marker','none') findall(gcf,'Marker','.')];
set(a,'LineWidth',lineWidth,'Marker','.','MarkerSize',lineCover);
Oleg Komarov
Oleg Komarov 2011년 4월 19일
Nice idea, it reminds me of the option you have in excel to chose the ending of a line!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Matt Fig
Matt Fig 2011년 4월 14일
I don't have the correct toolbox so I cannot test these ideas, but two come to mind. I assume that what looks like blue lines in your image are actually LINE objects.
1. Extending two of the lines (opposite sides) so as to close the gaps. This one would be tricky to get right.
2. Use the coordinates of the lines to create rectangles using the RECTANGLE function. This would be somewhat easier than the above. After the rectangles were created the blue lines could be deleted.

Matt Tearle
Matt Tearle 2011년 4월 14일
From my experiments, it appears to be a combination of what Matt Fig said, and just the translation to png. This worked OK for me (annoying as it is):
h = boxplot(x);
set(h,'LineWidth',4)
set(h(7,:),'MarkerSize',10)
replaceboxes
Then File -> Save As and save as emf. Then open the emf in Paint (or whatever) & File -> Save As to save as png.
The last step is optional: slap forehead with palm of hand and shake head sadly.
The magic replaceboxes function:
function replaceboxes
h = findobj('tag','Box');
n = length(h);
for k = 1:n
x = get(h(k),'XData');
y = get(h(k),'YData');
c = get(h(k),'Color');
l = get(h(k),'LineWidth');
ht = y(2)-y(1);
wd = x(3)-x(1);
rectangle('position',[x(1),y(1),wd,ht],'EdgeColor',c,'LineWidth',l)
end
delete(h);
  댓글 수: 3
Oleg Komarov
Oleg Komarov 2011년 4월 14일
doh...you were faster:
% Create example boxplot
h = boxplot(randn(100,4));
% Set linewidth to 10
set(h,'linewidth',6)
% Retrieve coordinates of the bodies (boxes)
data = get(h(5,:),{'XData','YData'});
for b = 1:size(h,2)
% Create rectangle
pos = [data{b,1}(1) data{b,2}(1) -diff(data{b,1}(end-1:end)) diff(data{b,2}(1:2))];
rectangle('pos',pos,'edgec','b','linew',6)
% Delete box
delete(h(5,b))
end
Jessica Lam
Jessica Lam 2012년 8월 9일
From my experiment, it seems to be disable to save one .png file as a nice box for great linewidths . Please find the following code for your ref. Any suggestions? Thanks .
x = 1:10; y=rand(10,1);
h = boxplot(x);
set(h,'LineWidth',4)
set(h(7,:),'MarkerSize',10)
h = findobj('tag','Box');
n = length(h);
for k = 1:n
x = get(h(k),'XData');
y = get(h(k),'YData');
c = get(h(k),'Color');
l = get(h(k),'LineWidth');
ht = y(2)-y(1);
wd = x(3)-x(1);
rectangle('position',[x(1),y(1),wd,ht],'EdgeColor',c,'LineWidth',l)
end
delete(h);
print('-dpng', 'test.png', '-r100');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by