📚 The CoCalc Library - books, templates and other resources
License: OTHER

licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Advanced Graphing Features
These notes provide instructions for some advanced graphing features in Sage. They are provided here for future reference; you will not need these for the assignment today.
Adding a Legend
We can add a legend using the legend_label option. Make sure you add it to all the plots.
Your labels can be whatever string you want (just make sure it's all in quotes).
Labelling the Axes
We can also label the axes using the axes_labels option (you only need to add this to one of the plots). Notice the square brackets.
Here's another example.
Changing Line Thickness
Make the curves thicker with the "thickness" option.
Shading
To shade the area under a curve, add the option fill='axis'
You can also shade the area between and by adding fill=g to the plot for . Notice that there are no quotes around g.
You could get the same thing by adding fill=f to the plot of instead.
Adding a Title
Add a title using the title option. You add this to just one of the plots.
Adding Text to Plots
In addition to titles and axis labels, you can add any text to a plot using the "text" command. You specify any string within quotation marks along with an ordered pair specifying the location.
Here is an example. This inserts the string "some text" centered at the point .
Here is another example. I have changed the text color to black, and I have rotated the text 45 degrees.
You can also adjust the size using the "fontsize" option, which specifies the size in points (the default is 10).
If you put fontsize in the plot, it will change the size of the tick mark labels, as well as axis labels and the title.
Notice how the y-axis label and the title overlap in the example below.
We can use the text command to put the axis label to the side of the y-axis.
For some reason, the font size is different for the x and y labels, so it may be better to use "text" for both.
Here's a final example.
Adding Text with Math Symbols
If you want to add text to a plot that includes math symbols, then you can use (see "Writing in Sage" notes). Put $ signs around the code.
For technical reasons (having to do with Python), you should use a "raw string" within the text command. This means you add the letter "r" before the first quotation mark. This is not always necessary, but sometimes leaving off the r will have irritating results.
Here is an example.