3
$\begingroup$

I have a set of functions I have plotted them in one single figure. The following are my concerns. 1. I tried to fix the legends for this figure, but unable to do this 2. Is there any way that I can plot these functions in black with different styles. I tried using the absolute dashing function to do this, and I got what I was looking for, but the problem is I need to do this separately for all the functions and later use the show function to merge them. Are there any ways that I can automate this?

fixedfree = Table[Sin[(2*i - 1)/(2)*π*x2], {i, 1, bmc}]
    barmodes = Flatten[{fixedfree}];
    p9 = Plot[barmodes, {x2, 0, 1}, 
      PlotLegends -> {"Mode 1", "Mode 2", "Mode 3", "Mode 4", "Mode 5"}]
$\endgroup$
6
$\begingroup$

Use the option PlotTheme -> "Monochrome" :

Plot[barmodes, {x2, 0, 1}, PlotTheme->"Monochrome",
  PlotLegends -> {"Mode 1", "Mode 2", "Mode 3", "Mode 4", "Mode 5"}]

enter image description here

Update: In version 11 (Windows 7) , "I got the plot style but still, legends are not appearing in the plot."

Try creating the legend separately and combine it with plot using Legended:

monochromestyles = "DefaultPlotStyle"  /. (Method /. 
     Charting`ResolvePlotTheme["Monochrome", Plot]);

legend = LineLegend[ monochromestyles, {"Mode 1", "Mode 2", "Mode 3", "Mode 4", 
    "Mode 5"}];

Legended[Plot[barmodes, {x2, 0, 1}, PlotTheme -> "Monochrome"], legend]

same picture

Update 2: To place the legend above the plot:

legend = LineLegend[monochromestyles, {"Mode 1", "Mode 2", "Mode 3", "Mode 4", 
        "Mode 5"}, LegendLayout -> {"Row", 1}];

Legended[Plot[barmodes, {x2, 0, 1}, PlotTheme -> "Monochrome", 
  ImageSize -> {500, 300}], Placed[ legend, Above]]

enter image description here

$\endgroup$
  • $\begingroup$ I got the plot style but still, legends are not appearing in the plot. I copied paste the same code $\endgroup$ – acoustics Jul 27 '19 at 14:22
  • $\begingroup$ @acoustics, probably version/os issue. This works fine in version 12 (Wolfram Cloud). $\endgroup$ – kglr Jul 27 '19 at 14:24
  • $\begingroup$ I am using wolfram 11 in windows 7, is there any ways to resolve this without reinstalling the advanced version $\endgroup$ – acoustics Jul 27 '19 at 14:27
  • 1
    $\begingroup$ yes sir it is working in the current version. solved the problem $\endgroup$ – acoustics Jul 27 '19 at 15:29
  • 1
    $\begingroup$ @acoustics, please see update 2. $\endgroup$ – kglr Jul 29 '19 at 6:15
4
$\begingroup$

Here's another way, using increasingly spaced dashing.

bmc = 5;
fixedfree = Table[Sin[(2*i - 1)/(2)*\[Pi]*x2], {i, 1, bmc}];
barmodes = Flatten[{fixedfree}];
customdashing[i_] := Dashing[{0, 0.001*3 i, 0.001*3 i}];
p9 = Plot[barmodes, {x2, 0, 1}, 
  PlotStyle -> Table[Directive[Black, customdashing[i]], {i, 1, bmc}],
   PlotLegends -> {"Mode 1", "Mode 2", "Mode 3", "Mode 4", "Mode 5"}]

monochrome

Note the customdashing function. The result isn't quite as distinctive as the PlotTheme answer, but it should work on any version. To customise the result, you can try changing the factor in the customdashing function from 3i to some larger value like 5i.

$\endgroup$
  • $\begingroup$ Is there any way that I can change the font size of the legend? $\endgroup$ – acoustics Jul 27 '19 at 15:37
  • 1
    $\begingroup$ Yes, instead of "Mode 1" use Style["Mode 1", FontSize->value] $\endgroup$ – Musang Jul 27 '19 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.