Combining Plots of Data and Functions

1. Introduction

We will often have to compare different functions and/or data sets and the best way to do that is to plot them together on a single graph. The command below show how this is done for a black-and-white printer like the ones used in the Physics Teaching labs.

2. Plotting Data.

Below we take two sets of data and plot them with different markers (using the PlotMarkers option) to distinguish between them in the final graph. The number in the list containing the marker is for the size of the marker. You can choose your own symbol by going to the Mathematica menu bar and clicking on Palettes and then highlighting Special Characters. You should see a new menu appear. Click on the Symbols tab and then on the “light bulb” (💡) icon. You should now see a selection of markers that can be used to represent the points in your plot.

data1={{0.0481,0.0009766},{0.0482,0.005},{0.0483,0.019},{0.0484,0.029},{0.0485,0.037},{0.0486,0.045},{0.0487,0.052},{0.0488,0.059},{0.0489,0.065},{0.049,0.071},{0.0491,0.077},{0.0492,0.082},{0.0493,0.087},{0.0494,0.092},{0.0495,0.096},{0.0496,0.101},{0.0497,0.105},{0.0498,0.109},{0.0499,0.112},{0.05`,0.116}};
p1=ListPlot[data1,PlotMarkers->{"▼",10}] (* Use inverted triangles to plot the data. *)

Plot a second data set with a different marker.

data2={{0.0481,0.01917},{0.0482,0.026399},{0.048299,0.0366018},{0.0484,0.04380},{0.048499,0.051018},{0.0486,0.05720},{0.048699,0.0624179},{0.048799,0.0666},{0.0489,0.0707},{0.04899,0.07518},{0.0491,0.0792},{0.049199,0.082417},{0.0493,0.08560},{0.0494,0.08879},{0.049499,0.091017},{0.049599,0.093218},{0.04969,0.095418},{0.0498,0.0976},{0.0499,0.0998},{0.05,0.1009}}
p2=ListPlot[data2,PlotMarkers->{"●",5}]

Now combine the plots.

p3=Show[p1,p2,PlotRange->{{0.048,0.050},{0.0,0.14}},Frame->True,FrameLabel->{"x","y","Examples of Marker Styles"},
ImageSize->6.5*72,BaseStyle->FontSize->16]

3. Plotting Functions.

Now we plot two functions with different line styles (using the PlotStyle option) to distinguish between them in the final graph. The number in the argument of Dashing in the first example below determines the length of the dashes. The number in the argument of GrayLevel in the third example below determines the darkness of the line.

p4=Plot[Sin[x],{x,0,30},PlotStyle->Dashing[0.02]]
p5=Plot[Sin[x+2.5],{x,0,30},PlotStyle->Dotted]
p6=Plot[Sin[x+7.5],{x,0,30},PlotStyle->GrayLevel[0.2]]
Show[p4,p5,p6,Frame->True,FrameLabel->{"x","y","Examples of Line Styles"},
BaseStyle->FontSize->16]