Message Boards Message Boards

0
|
3161 Views
|
16 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Minor gridlines and other plot questions

Posted 1 year ago
  1. I am trying to show minor and major gridlines on a ListLinePlot. I tried several of the suggestions from StackExchange and the nearest I could get is in the attached notebook. The vertical gridlines are fine but the major horizontal gridlines are misaligned.

  2. At the moment I am using FrameLabel but I would like the y-axis label (pH) to be oriented horizontally instead of vertically. If this is not possible with FrameLabel, how could I use AxesLabel to place labels to the left and below the axes and with the y-axis label oriented horizontally.

  3. I have been experimenting with PlotMarkers and LegendMarkerSize and this is what I have found

enter image description here

but neither of these affects the size of the markers on the plot lines, so how do I change the size of those?

4 Is it possible to place a frame around the legend? If possible I would like to have a frame around the legend and position it at the bottom right of the plot area (instead of below the axis label)

POSTED BY: Paul Newton
16 Replies
Posted 1 year ago

I'll give that a try, just for the fun of it, and I'll keep looking for information about "standard" markers. If I find anything I'll report back here. Thanks again.

POSTED BY: Paul Newton

You've reached the limits of my knowledge! I don't know where the 'standard' markers live, or what format they are. But you can make open markers with the respective shapes and specifying FaceForm. Open circles would be something like

Graphics[{FaceForm[None],EdgeForm[Thickness[0.x]],Circle[]}]
POSTED BY: Gareth Russell
Posted 1 year ago

Yes, I saw in the documentation that you can you use pretty much anything as a marker, but if you let Mathematica decide on the markers some of the ones used are a circle, an up triangle, a diamond and so on. I wondered if there is a list somewhere of the "standard" markers. Also can "OpenMarkers" be used in conjunction with, for example, Graphics[Disk[]?

POSTED BY: Paul Newton

Those shapes are inside Graphics[]. Any Graphics[] object can be a marker, so pretty much whatever you like. The documentation shows an example using a Wolfram 'spikey' (i.e., a polyhedron).

I don't know a better way to do major and minor gridlines.

POSTED BY: Gareth Russell
Posted 1 year ago

Many thanks for that - your help is much appreciated. A couple of points:

I don't think

Mesh -> All, MeshStyle -> {PointSize[0.01], Default} is still needed

Apart from Disk[] and Rectangle[] what other marker styles are there? And, pushing my luck, do you have any thoughts on the gridlines?

POSTED BY: Paul Newton

Fair enough! The issue with the marker size is that you are using characters (i.e. a font), and the scaling number doesn't affect that. Here is a slightly simplifed version that does what you want.

ListLinePlot[{Reverse[dataPairs1, 2], Reverse[dataPairs2, 2]},
 Frame -> True, PlotRange -> {{0, 20}, {0, 14}},
 FrameLabel -> {Style["Vb/\!\(\*SuperscriptBox[\(cm\), \(3\)]\)", 12],
    Rotate[Style["pH", 12], -90 Degree]},
 PlotLabel -> 
  Style["Titration of weak acids with sodium hydroxide", 16, Bold, 
   FontFamily -> Default, FontColor -> Black], 
 PlotStyle -> {Red, Blue},
 PlotMarkers -> {{Graphics[Disk[]], 13}, {Graphics[Rectangle[]], 12}},
  Mesh -> All, MeshStyle -> {PointSize[0.01], Default}, 
 GridLines -> {gridLinesF[], gridLinesF[]},
 PlotLegends -> 
  Placed[
   LineLegend[{"Acetic acid", "2-chloroaniline"}, 
    LegendFunction -> (Framed[#, FrameMargins -> -2, 
        Background -> Yellow, FrameStyle -> Directive[Red]] &), 
    LegendLayout -> "Row", LegendMarkers -> Automatic, 
    LegendMarkerSize -> {{30, 13}, {30, 12}}, 
    LabelStyle -> {FontSize -> 10}], {Right, Bottom}]]
POSTED BY: Gareth Russell
Posted 1 year ago

It's really just for the challenge - I like to stretch myself and experiment with what I can achieve (even if I do some help along the way). I know that I can do these things in Excel and I want to be able to do the same things in Mathematica.

POSTED BY: Paul Newton
Posted 1 year ago

As always, there is more than one way to skin a cat!

POSTED BY: Paul Newton

Can I ask why you are going to all this trouble to make super-fine adjustments to the plot parameters?Have you been given a style that you are required to match precisely?

POSTED BY: Gareth Russell

Also, it is surprising to me that RotateLabel->False doesn't do what you (and I) expect it to. It works in Graphics[] objects, but seemingly not in ListPlot[] and other functions. Maybe a bug!

However the simpler workaround is this:

FrameLabel -> {"xlabel", Rotate["label", -90 Degree]}

POSTED BY: Gareth Russell
Posted 1 year ago

I have sorted the axes labels and the legend but gridlines and the style of the plots themselves are still a problem. In particular, PlotMarkers -> {{\[FilledSmallCircle], 10}, {\[FilledSquare], 10}} is changing the marker shape in the legend but not on the plot itself. I am using this to change the size of the markers on the plot

Mesh -> All, MeshStyle -> {PointSize[0.01], Default}

The complete code for the plot is here

Labeled[ListLinePlot[{Reverse[dataPairs1, 2], Reverse[dataPairs2, 2]},
   Frame -> True, PlotRange -> {{0, 20}, {0, 14}}, 
  PlotLabel -> 
   Style["Titration of weak acids with sodium hydroxide", 16, Bold, 
    FontFamily -> Default, FontColor -> Black], 
  PlotLegends -> 
   Placed[LineLegend[{"Acetic acid", "2-chloroaniline"}, 
     LegendFunction -> (Framed[#, FrameMargins -> -2, 
         Background -> Yellow, FrameStyle -> Directive[Red]] &), 
     LegendLayout -> "Row", LegendMarkerSize -> {{10, 12}}, 
     LabelStyle -> {FontSize -> 10}], {Right, Bottom}], 
  ImageSize -> 550, PlotStyle -> {Red, Blue}, 
  PlotMarkers -> {{\[FilledSmallCircle], 10}, {\[FilledSquare], 10}}, 
  Mesh -> All, MeshStyle -> {PointSize[0.01], Default}, 
  GridLines -> {gridLinesF[], gridLinesF[]}], {Style["pH", 12], 
  Style["Vb/\!\(\*SuperscriptBox[\(cm\), \(3\)]\)", 12]}, {Left, 
  Bottom}, RotateLabel -> False]

I have also attached my latest the notebook with what I have got so far. I still need to set the style and size of the markers on the plot, and set the line style of each plot/series. And sort out the grid lines!

Attachments:
POSTED BY: Paul Newton
Posted 1 year ago

Thank you for the explanation Gareth

POSTED BY: Paul Newton

To change the legend placement and make it more precise, instead of using defined words like Center, use a formulation like this:

Placed[LineLegend[], {{1, 0}, {1, 0}}]

The first coordinates are scaled to the overall figure (bottom right), and the second coordinates are scaled to the legend itself (also bottom right). So this says to place the legend so that its bottom right corner aligns with the bottom right corner of the graphic. To move it in a bit, you might use

Placed[LineLegend[], {{0.95, 0.05}, {1, 0}}]

Experiment with the numbers and you will get the idea.

POSTED BY: Gareth Russell

The & indicates a pure function (one without an assigned name). In pure functions, the inputs are represented by # symbols (#1, #2, etc.. # is the same as #1). In this case you are defining a specific Framed[] function which will will be applied to the legend, so the # 'stands in' for the legend.

POSTED BY: Gareth Russell
Posted 1 year ago

Solved #4 with

LegendFunction -> (Framed[#, FrameMargins -> -2, Background -> Yellow,
     FrameStyle -> Directive[Red]] &)

But I would like to know the purpose of # and &

POSTED BY: Paul Newton
Posted 1 year ago

I believe I have solved #2 (axis labels) by removing FrameLabel and RotateLabel from ListLinePlot [.....]

Then I can do this

Labeled[ListLinePlot[.....], {"pH","Vb"}, {Left, 
  Bottom}, RotateLabel -> False]

Still looking for answers to the other items ...

POSTED BY: Updating Name
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