Message Boards Message Boards

0
|
3986 Views
|
6 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Pass options to function when using Postfix

Posted 2 years ago

Consider the following command:

Thread[{{1, 2, 3, 4}, {1, 4, 9, 16}}] // ListPlot

Now I want to pass into ListPlot the following option:

PlotStyle -> Black

so that the points appear in black color. Obviously, one can simply do

    ListPlot[
     Thread[{{1, 2, 3, 4}, {1, 4, 9, 16}}]
     , PlotStyle -> Black]

But I would like to be able (if possible at all) to pass this black color additional option into ListPlot when I use the Postfix syntax.

Any idea about that?

POSTED BY: Ehud Behar
6 Replies
Posted 2 years ago

You could also use Alan Calvitti's magical "bullet" operator from this post.

\[Bullet] /: f_[pre___, \[Bullet], post___] := 
  With[{n = Length[List@pre], m = Length[List@post]}, 
   Curry[f, Join[Range[n], {n + m + 1}, Range[m] + n]][pre, post]];

After evaluating it

Thread[{{1, 2, 3, 4}, {1, 4, 9, 16}}] // ListPlot[\[Bullet], PlotStyle -> Black]

On a Mac \[Bullet] is Option + 8

POSTED BY: Rohit Namjoshi
Posted 2 years ago

If one feels that & and # are somewhat cryptic, here is an alternative to Gustavos example:

Thread[{{1, 2, 3, 4}, {1, 4, 9, 16}}] // Function[points, ListPlot[points, PlotStyle -> Black]]
POSTED BY: Hans Milton

If you don't like having too many & and # you can also do this:

Thread[{{1, 2, 3, 4}, {1, 4, 9, 16}}] //
    OperatorApplied[ListPlot][PlotStyle->Black]

For more than one option, put them in a list:

Thread[{{1, 2, 3, 4}, {1, 4, 9, 16}}] //
    OperatorApplied[ListPlot][{PlotStyle->Black, Frame->True}]
POSTED BY: Gustavo Delfino
Posted 2 years ago
Thread[{{1, 2, 3, 4}, {1, 4, 9, 16}}] // ListPlot[#, PlotStyle -> Black] &
POSTED BY: Hans Milton
Posted 2 years ago

@Hans Milton Thanks a lot! This is what I was looking for, opeartor form.

POSTED BY: Ehud Behar

This does the trick for your example

plot = Thread[{{1, 2, 3, 4}, {1, 4, 9, 16}}] // ListPlot;

plot/._RGBColor:>Black
POSTED BY: Marcelo Guzmán
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract