Message Boards Message Boards

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

Insert::ins warning/error occurs when switching on/off plots

Posted 1 year ago

Attached is some code demonstrating a problem I've come across when switching plots on or off by a checkbox control. The Insert::ins warning comes up if two plots are unchecked. I'm not sure what triggers the warning. If the plot labels are removed the warnings vanish. I'd like to keep the labels.

G

POSTED BY: Gerald Proteau
11 Replies

What is the cause of this bug if i may ask.

G

POSTED BY: Gerald Proteau

I'm running 13.1.0 for Microsoft Windows 11 (64-bit) (June 16, 2022)". Working with a fresh kernel does nothing. G

POSTED BY: Gerald Proteau
Posted 1 year ago

13.2.0.0 on Mac. Here are some minimal examples:

The following doesn't generate messages, but it does have a dangling plot label. No combination of None for PlotStyle generated the messages when there were two plots.

Plot[{Sin[x], Cos[x]}, {x, 0, 6}, PlotStyle -> {None, None}, PlotLabels -> {"f1", "f2"}]

With three plots, the presence of PlotLabels is definitely a factor. The following works in the sense of not generating any messages, and no combination of None for PlotStyle generated the messages.

Plot[{Sin[x], Cos[x], Log[x]}, {x, 0, 6}, PlotStyle -> {None, None, None}]

With three or more plots and the presence of PlotLabels, all of the following generate messages:

Plot[{Sin[x], Cos[x], Log[x]}, {x, 0, 6}, PlotStyle -> {None, Green}, PlotLabels -> {"f1", "f2", "f3"}]
Plot[{Sin[x], Cos[x], Log[x]}, {x, 0, 6}, PlotStyle -> {None, Green, None}, PlotLabels -> {"f1", "f2", "f3"}]
Plot[{Sin[x], Cos[x], Log[x]}, {x, 0, 6}, PlotStyle -> {Green, None, None}, PlotLabels -> {"f1", "f2", "f3"}]

If the final plot style is not None, or if there are fewer than 2 None (but a full set of three styles), then no error messges are generated. The following all work.

Plot[{Sin[x], Cos[x], Log[x]}, {x, 0, 6}, PlotStyle -> {None, None, Green}, PlotLabels -> {"f1", "f2", "f3"}]
Plot[{Sin[x], Cos[x], Log[x]}, {x, 0, 6}, PlotStyle -> {None, Red, Green}, PlotLabels -> {"f1", "f2", "f3"}]
Plot[{Sin[x], Cos[x], Log[x]}, {x, 0, 6}, PlotStyle -> {Red, None, Green}, PlotLabels -> {"f1", "f2", "f3"}]
Plot[{Sin[x], Cos[x], Log[x]}, {x, 0, 6}, PlotStyle -> {Red, Green, None}, PlotLabels -> {"f1", "f2", "f3"}]
POSTED BY: Eric Rimbey

Thanks for your help, I've tried several of these and still the error pop up on my desktop. I might have to consider an upgrade to 3.2, If that helps with the program. I did not anticipate this bug.

G

POSTED BY: Gerald Proteau
Posted 1 year ago

Yes, I was trying to document when the problem does and does not occur.

POSTED BY: Eric Rimbey

Talking with support updating won't help as this bug is not addressed to in the next version. I'm going to try simply re-coloring a switched off plot and its label to the background label. Brutal but it might work.

G

POSTED BY: Gerald Proteau
Posted 1 year ago

The easiest workaround here would probably be to just wrap Quiet around the Plot expression. As far as I can tell, the messages are superfluous--the plots all look fine.

I will say that your particular approach here is a bit indirect. I'm referring to using the Ifs and using a "code" for the Manipulate variables. If you want to be able to make easy changes or additions to this (like adding new functions or being able to easily adjust the individual stylings), you might consider a more data-driven approach. Here's an example.

Start by creating a data structure to hold the parameters:

PlotData =
  <|"f1" ->
    <|"label" -> "function 1",
     "function" -> (Sin[x^#] &),
     "style" -> {GrayLevel[0], Thickness[.005]}|>,
   "f2" ->
    <|"label" -> "function 2",
     "function" -> (Cos[# x] &),
     "style" -> {GrayLevel[0.4], Thickness[.005]}|>,
   "f3" ->
    <|"label" -> "function 3",
     "function" -> (2 Sin[# x] &),
     "style" -> {GrayLevel[0.8], Thickness[.005]}|>|>;

Now you can simplify the Manipulate a bit:

Manipulate[
 With[
  {fns = Lookup[Lookup[PlotData, selected, {}], "function", Null],
   labels = Lookup[Lookup[PlotData, selected, {}], "label", Null],
   styles = Lookup[Lookup[PlotData, selected, {}], "style", Null]},
  Plot[Evaluate[#[a] & /@ fns], {x, 0, 6}, 
   PlotLabels -> Placed[labels, {{Scaled[1], Before}}], 
   PlotStyle -> styles,
   PlotLabel -> "Initial Sag and Tension",
   ImageSize -> {400*1.618, 400},
   AspectRatio -> Automatic]],
 {{selected, Keys[PlotData]}, Keys[PlotData], CheckboxBar, ControlPlacement -> Left, Appearance -> ("Horizontal"), ImageSize -> Tiny},
 {a, 1, 3}]

One minor issue here is that when there is only a single plot, using a List for the plot labels shows the label as a list in the plot. I'd probably create a helper function:

NormalizeSingleton[{elem_}] := elem;
NormalizeSingleton[other_] := other;

and use it like this (in the With expression's variable definitions):

labels = NormalizeSingleton[Lookup[Lookup[PlotData, selected, {}], "label", Null]]
POSTED BY: Eric Rimbey

Thanks very much for your help and examples. Your code creating a data structure holding plot parameters is interesting and I will want to use something similar in another part of the program I'm putting together.

G

POSTED BY: Gerald Proteau

I wonder if turning off the message would help. G

POSTED BY: Gerald Proteau

I note the warnings are not showing up on the online version. Here are the warnings I receive on my desktop copy.

Insert::ins: Cannot insert at position {3} in {{{1.2244910^-7,1.2244910^-7},{0.00184031,0.00184031},{0.00368049,0.00368048},{0.00736086,0.0073608},{0.0147216,0.0147211},{0.0294431,0.0294388},{0.058886,0.058852},{0.117772,0.1175},{0.24545,0.242993},{0.364667,0.356638},<<424>>}}

Insert::ins: Cannot insert at position {3} in {{{1.2244910^-7,1.2244910^-7},{0.00184031,0.00184031},{0.00368049,0.00368048},{0.00736086,0.0073608},{0.0147216,0.0147211},{0.0294431,0.0294388},{0.058886,0.058852},{0.117772,0.1175},{0.24545,0.242993},{0.364667,0.356638},<<424>>}}

Insert::ins: Cannot insert at position {3} in {{{1.2244910^-7,1.2244910^-7},{0.00184031,0.00184031},{0.00368049,0.00368048},{0.00736086,0.0073608},{0.0147216,0.0147211},{0.0294431,0.0294388},{0.058886,0.058852},{0.117772,0.1175},{0.24545,0.242993},{0.364667,0.356638},<<424>>}}

General::stop: Further output of Insert::ins will be suppressed during this calculation.

Callout::copos: {{Scaled[1],Before}} is not a valid position for the placement of callouts.

POSTED BY: Gerald Proteau

What desktop version are you using? Works fine for me on "13.2.1 for Mac OS X ARM (64-bit) (January 27, 2023)". Have you tried evaluating the code in a fresh kernel?

POSTED BY: Rohit Namjoshi
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