Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting issues with dash-dot and dotted lines: How to modify default linestyles for better use with vector renderer 'painters'?

Matlab offers the following default linestyles:

'-'     Solid line (default)
'--'    Dashed line
':'     Dotted line
'-.'    Dash-dot line

The first two are alright, the third : is absolutely not my taste and rendered badly and the last one -. is just usable with pixel renderers (openGL, zbuffer), otherwise it looks the same as --. But I'd like to render my graphs with painters for countless reasons. This way the dash-dot line becomes useless:

enter image description here

The dash-dot lines (blue, bright red) practically look the same like the dashed line (dark red). This is a 3000% zoom of my vector-graphic based PDF.

This is basically my code to generate the graphicss:

set(fig_handle, 'Units','centimeters','PaperUnits','centimeters')
set(fig_handle,'Position',[1 1 width height],...
       'PaperPosition',[0 0 width+margin height+margin],...
       'PaperSize',[width+margin height+margin],...
       'PaperPositionMode','auto',...
       'InvertHardcopy', 'on',...
       'Renderer','painters'...     
   );

saveas(fig_handle,name,'pdf')

Well I need a third linestyle, do you know any possibility to create a custom linestyle or to modify the existing ones? Increasing of the gaps between dashes and dots should already solve the problem.

Markers and the use of the pixel-renderers are no option!

Also some "custom" lines in means of "leaving out" values shouldn't be an option.

I'm thankful for any advice.

like image 538
Robert Seifert Avatar asked Feb 13 '23 17:02

Robert Seifert


1 Answers

MATLAB's plotting routines used to be top-notch. They were so much better than those of the competition that they were a reason to buy MATLAB for many people.

This has changed however. They seem rather like a blast from the past now, when compared to plots from Mathematica, SciLab, and others. They don't look very pretty, they have lots of issues with different-then-standard rendering engines, customizability is rather poor, even simple changes can be quite complicated to effect, etc.

Don't get me wrong, they're still pretty good, but they are no longer a reason to buy the product anymore. I've even heard some potential new users deciding for one of its competitors, in part based on how graphics look.

MathWorks is of course more than aware of this. They are rather slow to respond (I assume they have some difficulties), but I know they have been working on a major overhaul of the graphics algorithms and utilities for over 4 years now.

It's called called hg2, short for handle graphics v. 2. It's already been available in MATLAB since 2010, but then it was completely undocumented, buggy, hard to use, etc.

This has however improved steadily over the years, and now it's actually quite usable (although still unsupported, officially). Yair Altman (from UndocumentedMatlab.com) wrote a nice in-depth article on the subject.

This has the functionality you need, and then some :)

EDIT: I just got an e-mail from John Kelly, the current administrator from MATLAB central. The first few lines:

The R2014b prerelease is now available for download. This version of MATLAB contains many new features including a new graphics system. There are changes in the R2014b graphics system that may affect the operation of existing code. As an author of a popular File Exchange submission, we would like to encourage you to download the R2014b prerelease so that you have an opportunity to make changes to your submission in preparation for the release of R2014b.

So R2014b finally ships with an official hg2 :)

like image 198
Rody Oldenhuis Avatar answered Feb 15 '23 09:02

Rody Oldenhuis