nice boxes for great linewidths
古いコメントを表示
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.
採用された回答
その他の回答 (2 件)
Matt Fig
2011 年 4 月 14 日
2 投票
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
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 件のコメント
Matt Fig
2011 年 4 月 14 日
I am glad someone tried that idea! I wish I could have done it, but I don't like to post untested code...
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
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');
カテゴリ
ヘルプ センター および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!