kakearney / contourfcmap-pkg

Create a filled contour plot in Matlab, with better color-to-value clarity
MIT License
17 stars 2 forks source link

feature request: contourf kwargs for line properties #9

Open briochemc opened 2 years ago

briochemc commented 2 years ago

First things first, congratulations, this is such a neat package!

Hopefully this is request is little work. It would be great if the keyword (value/pair) arguments of contourf were also valid for contourfcmap. For instance, I am looking for the line properties, such as LineColor, LineStyle, and LineWidth. The motivation is to be able to customize plots as below for example

Screen Shot 2022-04-15 at 2 00 50 pm

which is done by first plotting without the lines via

contourf(.., 'LineStyle', 'none')

and then adding the specific lines of interest back with simple contour calls, e.g.,

contour(.., 'LineStyle', 'dash')

for example.

Because any contour line style/color can be added after removing them all, my request can probably be reduced to being able to pass the LineStyle, i.e.,

contourfcmap(.., 'LineStyle', 'none')

Or, even better IMHO,

contourfcmap(.., linestyle="none")

with the more "modern" keyword argument syntax.

I realize this would probably require figuring out some syntax for controlling the colorbar ticks and tick labels, but maybe I'm wrong?

kakearney commented 2 years ago

You can always modify these sorts of properties after the fact by saving the handles to the contourfcmap object(s), which are returned by the optional output argument. Handles are provided for everything created, including contourgroups (recolor method only), patches (calccontour method only), and the psuedocolorbar child objects (axis, colorbar, patches).

Properly parsing contour properties and applying them as part of the contourfcmap call would not be a trivial task. I probably won't add that capability unless I find an example where modifying the properties after creation does not suffice. Likewise for the more modern keyword syntax, which would be a bear to keep back-compatible. So sorry. :-)

briochemc commented 2 years ago

Not sure how far you want to keep backwards compatibility, but FWIW, I've been using the "new" argument validation (introduced in R2019b) and it works like a charm to handle old and new syntax. Here's an example with contour properties:

function custom_contourf(z, opt)
    arguments
        z
        opt.?matlab.graphics.chart.primitive.Contour % Accept all contour key-value pair args
        opt.LineStyle = ':' % set one default one
    end

    optcell = namedargs2cell(opt); % convert struct to cell of key-value pairs
    contourf(z, optcell{:}, 'linestyle', 'none'); % filled contour without lines
    hold on
    contour(z, 'linecolor', 'black', optcell{:}); % contour lines added
end

and then old and new syntax should work automatically:

>> custom_contourf(z)
>> custom_contourf(z, linestyle='--') % new syntax
>> custom_contourf(z, 'linestyle', '--', 'linecolor', 'red', 'linewidth', 5) % old syntax + extra changes

plots those:

If you are OK with this approach, I can try a PR when I find the time :)