How do I create graphics for publication in Mathematica?

This basic example shows how to create a graphic to be used for publication. In the end, the graphic below, showing the final results of the analysis of experimental data, will be created with just a few commands. In this particular example, we will go through the steps to explain how to create each element in the graphic below.

Importing and ploting the original data set

First, import and plot the original data set using the command ListPlot. More information on both Import and ListPlot are available in the Help Browser.

mydata  =  
        Import["C:\\desk\\Demo\\How-to\\DQA\\BreastCancer2.dat"];

mydata

dataplot = ListPlot[mydata];

Adding a frame and frame labels

Add a frame to the plot of our data using the option Frame->True. This is just one of many options to ListPlot. For more information on options look in the Help Browser or evaluate Options[ListPlot]. In addition to its own specific options, ListPlot also accepts the same options as Graphics.

ListPlot[mydata, Frame -> True];

ListPlot[mydata, AxesOrigin -> {30, 40}, 
        Frame -> True];

Now add frame labels to label the x and y axes using FrameLabel->{Temperature, Mortality}. More information on FrameLabel is available in the Help Browser.

ListPlot[mydata, AxesOrigin -> {30, 40}, Frame -> True,  
        FrameLabel -> {Temperature,  Mortality}];

Adding plot labels

PlotLabel provides a convenient way to add titles to plots.

ListPlot[mydata, AxesOrigin -> {30, 40}, Frame -> True,  
        FrameLabel -> {Temperature,  Mortality},  
        PlotLabel ->  "Breast Cancer Mortality Rate Vs. Mean Annual \
Temperature"];

Using a font other than Courierrequires a bit more work. One of the easiest methods is to use DefaultFont to change all the fonts in the graphic.

ListPlot[mydata, AxesOrigin -> {30, 40}, Frame -> True,  
        FrameLabel -> {Temperature,  Mortality},  
        PlotLabel ->  "Breast Cancer Mortality Rate Vs. Mean Annual \
Temperature",  DefaultFont ->  {"Helvetica", 12}];

A less radical method is using TextStyle.

textdataplot = 
        ListPlot[mydata, AxesOrigin -> {30, 40}, Frame -> True,  
          FrameLabel -> {Temperature,  Mortality},  
          PlotLabel ->  "Breast Cancer Mortality Rate Vs. Mean Annual \
Temperature",  
          TextStyle ->  {FontFamily -> "Helvetica", 
              FontSize -> 12}];

TextStyle actually gives much more flexibility than DefaultFont. For example, it can also be used to set FontColor, FontWeight, and FontSlant. Below, I also add FontColor. Loading Graphics`Colors` allows to use color names rather than RGB tiplets.

<< Graphics`Colors`

ListPlot[mydata, AxesOrigin -> {30, 40}, Frame -> True,  
        FrameLabel -> {Temperature,  Mortality},  
        PlotLabel ->  "Breast Cancer Mortality Rate Vs. Mean Annual \
Temperature",  
        TextStyle ->  {FontFamily -> "Helvetica", FontSize -> 12,  
            FontColor -> Purple}];

Adding fits to graphs and changing colors

First, fit the data as is. Then, remove an outlier and refit the data.

myfit = Fit[mydata, {1, x}, x]

mynewdata = Delete[mydata, 15]

mynewfit = Fit[mynewdata, {1, x}, x]

Notice that the output of the fits above are equations. Therefore Plot has to be used to plot the fit. PlotStyle->RGBColor[] changes the line color to the RGB value.

firstfitplot = 
        Plot[myfit, {x, 31, 52}, 
          PlotStyle -> RGBColor[1, 0, 0]];

secondfitplot = 
        Plot[mynewfit, {x, 31, 52}, 
          PlotStyle -> RGBColor[0, 1, 0]];

The two fits can be shown with the original data plot using the Show.

alltogetherplot = 
        Show[textdataplot, firstfitplot,  secondfitplot];

Adding a legend

The Mathematica function Legend is part of the Graphics` packages. To use it, first load the package.

<< Graphics`Legend`

The two options to set are LegendPosition and LegendSize. LegendPosition can take values between {0, 0} (lower left corner of the graphic) and {1, 1} (upper right corner of the graphic). The parameters in LegendSize are fractions of the total size of the graphic.

\(\(ShowLegend[
        allcolorplot, {{{Graphics[{Blue, 
                  Line[{{0, 0}, {1, 
                        0}}]}], "Fit with Outlier"}, {Graphics[{EmeraldGreen, 
                  Line[{{0, 0}, {1, 0}}]}], "Fit without Outlier"}}, 
          LegendPosition -> { .5, \(- .4\)}, 
          LegendSize -> {0.8, \ 0.4}}];\)\)