9
$\begingroup$

I am having trouble making the dot marker for Cosec(x) larger. The plot points should be size 1% but the legend marker is super tiny and I don't know how to make it larger.

ClearAll[x]
g1 = Plot[Sin[x], {x, -3 Pi, 3 Pi}, PlotStyle -> Directive[Black, Thick, Dashed], PlotLegends -> {"Sin(x)"}, PlotRange -> {-3, 3}, Ticks -> {{-3 Pi, -2 Pi, -Pi, 0, Pi, 2 Pi, 3 Pi}, {-3, -2, -1, 0, 1, 2, 3}}];
ClearAll[x]; x = Table[{x, Csc[x]}, {x, -3 Pi, 3 Pi, 0.1}];
g2 = ListPlot[x, PlotStyle -> Directive[Red, PointSize -> 0.01], PlotLegends -> {"Cosec(x)"}];
Show[g1, g2, AxesLabel -> {"x", "y"}]

For clarity, here is the assignment question:

"Graded exercise 1: On the same graph, plot two functions, sin(x) and cosec(x) on the interval [-3[Pi],3[Pi]]. The function sin(x) should be plotted as a thick dashed black line and cosec(x) should be plotted as red points, with horizontal distance between points of 0.1; point size 1% of the total size. Label the horizontal axis "x" and the vertical axis "y". Provide an appropriate legend and choose an appropriate vertical range. [20%]"

$\endgroup$
  • $\begingroup$ Employing an example from the docs of PlotLegends: legend = Grid[{{Graphics[{Red, Disk[{0, 0}, 0.1]}, ImageSize -> 5], "Cosec(x)"}}]; g2 = ListPlot[x, PlotStyle -> Directive[Red, PointSize -> 0.01], PlotLegends -> legend]; $\endgroup$ – corey979 Oct 28 '16 at 13:14
  • 3
    $\begingroup$ Try PlotLegends -> SwatchLegend[{"Cosec(x)"}, LegendMarkerSize -> 20, LegendMarkers -> "Bubble"] instead of PlotLegends -> {"Cosec(x)"}? $\endgroup$ – kglr Oct 28 '16 at 13:23
  • $\begingroup$ I think this is a good question. the expectation is that there is some simple option to adapt the LegendMarkerSize. It seems from the two previous comments that this is may not be the case. Instead on has to either create a Graphics object oneself or use SwatchLegend. Both routes are more complicated than expected and hard to find via the help search function. (I had this problem under time pressure once and I couldn't sort it in Mathematica.) $\endgroup$ – tortortor Oct 29 '16 at 0:14
  • $\begingroup$ @kglr How'd you find out about that "Bubble" option? It's not in the documentation. $\endgroup$ – tparker Mar 8 '17 at 5:55
  • 1
    $\begingroup$ @tparker, it is mentioned in SwatchLegend >> Options >> LegendMarkers. You can get other built-in markers using ChartElementData[SwatchLegend]. $\endgroup$ – kglr Mar 8 '17 at 6:03
5
$\begingroup$

Using SwatchLegend[{"Cosec(x)"}, LegendMarkerSize -> 20, LegendMarkers -> "Bubble"] as the setting for PlotLegends in g2:

g2 = ListPlot[x, PlotStyle -> Directive[Red, PointSize -> 0.01], 
  PlotLegends-> SwatchLegend[{"Cosec(x)"}, LegendMarkerSize->20, LegendMarkers->"Bubble"]];

Show[g1, g2, AxesLabel -> {"x", "y"}]

Mathematica graphics

$\endgroup$

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.