Plots are important in mathematics and novels.
We'll focus on the math...
To plot a simple function in Mathematica, you use ...
the Plot function.
The first argument is the function,
and the second argument is a list with the variable,
starting point, and stopping point for the graph.
The result is a lovely plot.
Notice that the x-axis begins and ends at the values you specified.
While the y-axis extends from the minimum value to the maximum.
In other words,
you specify the domain, and Mathematica calculates the range.
Sometimes you'll want to change the size or aspect ratio of a plot.
Here's the graph of another function.
To see the bounding box, just click on the plot.
If you grab one of the handles on the border,
you can drag it to change the size of the graph.
When you do this, the aspect ratio remains the same.
If you'd like to change just the height,
hold down SHIFT and drag the bottom-center handle.
Similarly, to change the width,
you hold down SHIFT and drag the right-center handle.
When you plot a function,
Mathematica selects the aspect ratio for you
to make the graph as beautiful as possible.
To achieve this, Mathematica uses the golden ratio as the default aspect ratio.
The Golden ratio is the number (1 + sqrt(5)) /2.
This is the ratio of the width to the height which gives the most pleasing rectangle.
If you'd like to change this, use the Aspect Ratio option.
An aspect ratio of 1 gives a plot that's a square.
An aspect ratio of 2 gives a plot with a height of 2 and a width of 1.
Here's something to keep in mind.
The aspect ratio in Mathematica is the ratio of the height to the width,
while in images and video it's typically the width divided by the height.
To plot more than one function at a time,
you pass in a list of functions as the first argument.
Mathematica will automatically use different colors for each plot.
The range of the combined plots will be chosen so that all plots are visible.
Mathematica has so many ways to style a plot,
we'll discuss them in a dedicated video.
But we do want to cover a few common styling options.
By default, Mathematica will display tick marks on both the x- and y-axes.
If you want to hide these for any reason,
you use the Ticks option
with a value of None.
This will hide the ticks and the numerical labels as well.
On the other hand, you may want your graph to appear on a grid.
For this, use the GridLines option
with a value of Automatic.
This will display faint gridlines at each major tick mark on both axes.
If you only want specific gridlines to appear,
you can pass in a list of lists.
The first list contains the positions of the gridlines along the x-axis,
and the second list contains the locations of the gridlines on the y-axis.
By default, Mathematica will choose the smallest domain and range necessary to display your plot.
You can override this with the PlotRange option.
For this option, the word Range does not mean that it can only control the y-axis.
You can use this flexible option to fully control which parts of the graph are displayed.
If you provide a simple list with a min and max value,
Mathematica will use these values as the new y-min and y-max values...
even if this means parts of the plot will no longer be visible.
If you want to specify the bounds for both the x- and y-axes at the same time,
pass in a list of lists.
The first list has the x-min and x-max values,
and the second list contains the y-min and y-max values.
If you want Mathematica to choose the y-values for you,
use the All setting.
Another common adjustment to your plot
is to specify which tick marks should be numbered.
For this, you use the Ticks option again.
Like many options for the Plot function, this value is often a list of lists.
The first list controls the x-values,
and the second controls the y-values.
A quick way to specify the values is with the Range function...
When you use this option,
the numeric labels may become crowded.
Mathematica does a wonderful job at selecting default labels
so they provide the right balance between information and spacing.
If you override these values,
you may need to resize the Plot in order to find a size and aspect ratio that still looks good.
And remember in Mathematica you can use multiple options at the same time.
By changing the PlotRange...
Adding GridLines...
Specifying the Ticks...
And changing the Aspect Ratio...
You can quickly create a plot that focuses on those features you're interested in.
To learn more about Plotting and other Mathematica Essentials,
join our mailing list so you'll be notified when our professional course is available.