4

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.

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
  • Have you seen the following link: http://www.mathworks.com/matlabcentral/answers/97546-how-do-i-use-custom-line-styles-within-matlab I have used it before to effectively add a | linestyle (you can pretty much just copy and paste to achieve that), I haven't needed to do anything more advanced but maybe the methods used there will help you. They essentially reformat the data (without loss) to simulate a different linestyle. – Chris Jun 13 '14 at 12:18
  • You say `':'` is not your taste. Have you tried something like `'b-'` and on top of that, with the same data, `'w:'` (or some other color)? Maybe the resulting output will be slightly different than that of plain `':'` – Luis Mendo Jun 13 '14 at 12:22
  • @Chris Well, that's doing: *Also some "custom" lines in means of "leaving out" values shouldn't be an option.* - the problem is that you would need to write a custom function for every kind of plot, and there are a lot. Even it could be use for a `loglog` plot, with logarithmic distributed values, it can't be used for non-uniformly distributed values. – Robert Seifert Jun 13 '14 at 12:32
  • @LuisMendo that would indeed add some very few new possibilities, but I haven't got any pleasant combination. A simple `-.` which is working properly or even `-..` would be nice. Also it a very inconvenient solution to plot everything twice. (24 instead of already 12 plots... where does that end.) - Actually `:` is not rendered properly at all. – Robert Seifert Jun 13 '14 at 12:35
  • 1
    Have you seen [this](http://undocumentedmatlab.com/blog/hg2-update)? – Rody Oldenhuis Jun 13 '14 at 12:45
  • @Rody Wow Rody, wow. It seems Matlab has grown up. How nice looks that? And it works like a charm, even with all my complex plotting routines, just some very slightly changes were necessary (axes handles are now objects and not numbers anymore). And the vector plot works also very nice. You could post it as an answer, already best solution ;) – Robert Seifert Jun 13 '14 at 13:00
  • Worth mentioning the following solutions: [export_fig](http://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig), [fix_lines](http://www.mathworks.com/matlabcentral/fileexchange/23604-fix-lines), [fixPSlinestyle](http://www.mathworks.com/matlabcentral/fileexchange/17928-fixpslinestyle) – Amro Aug 16 '14 at 14:38

1 Answers1

8

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 :)

Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96
  • do you know a way to include the required parameter `-hgVersion 2` in Matlab without using a shortcut? I usually start Matlab by clicking a file, which wouldn't load HG2. – Robert Seifert Jun 13 '14 at 13:59
  • @thewaywewalk: You're on Windows? Then right click on any MATLAB file ⇒ open with... ⇒ choose default program ⇒ (point to your shortcut with `-hgVersion 2`) – Rody Oldenhuis Jun 13 '14 at 14:02
  • sounds great! Hope there are not too much more changes to the "leaked" version, as this works great ;) – Robert Seifert Jun 22 '14 at 10:09