Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Some Visualizations using CoCalc

Views: 1342

2D Graphics

The 2D graphics functionality built into Sage is modeled on Mathematica's 2d plotting. Many of the functions have the same names and input arguments.

Historically, this was initially largely written by Alex Clemesha, Mike Hansen, and me...

See the Sage Reference Manual » 2D Graphics

  • hundreds of examples, and a complete reference.

First half of Gregory Bard's book is on 2d graphics

x,y = var('x y') plot_vector_field((sin(x),cos(y^2)), (x,-3,3), (y,-3,3))
plot(x^2)

As new contributors to Sage came along, they didn't know that the point was to model the graphics API on Mathematica's, so it diverged, and you really must read the docs.)

This is from the mathematica docs:

Let's do this in Sage:

(For docs, type plot? or view the reference manual.)

# Plot[{Sin[x] + x/2, Sin[x] + x}, {x, 0, 10}, Filling -> {1 -> {2}}] plot( [sin(x) + x/2, sin(x) + x], (x, 0, 10), fill={0:[1]}) # Sin[x] + x/2 |--> sin(x) + x/2 --- use most standard math notation! # {Sin[x] ... } |--> [sinc(x) ...] --- use Python lists, which use square brackets # {x, 0, 10} |--> (x,0,10) --- Python tuples use parens instead of braces # Filling -> .. |--> fill= --- Sage uses "fill" instead of "filling", # and PYthon uses "=" instead of "->" # {1 -> {2}} |--> {0:[1]} --- Python uses 0-based like many very popular # programming languages...

Another example:

# ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}] # symbolic variables (except x) have to be declared %var x,y contour_plot(cos(x) + cos(y), (x, 0, 4*pi), (y, 0, 4*pi), cmap='copper_r')
# List of cmap options... import matplotlib.cm print(", ".join(matplotlib.cm.datad.keys()))
Spectral, summer, coolwarm, Wistia_r, pink_r, Set1, Set2, Set3, brg_r, Dark2, hot, PuOr_r, afmhot_r, terrain_r, PuBuGn_r, RdPu, gist_ncar_r, gist_yarg_r, Dark2_r, YlGnBu, RdYlBu, hot_r, gist_rainbow_r, gist_stern, gnuplot_r, cool_r, cool, gray, copper_r, Greens_r, GnBu, gist_ncar, spring_r, gist_rainbow, RdYlBu_r, gist_heat_r, Wistia, OrRd_r, CMRmap, bone, gist_stern_r, RdYlGn, Pastel2_r, spring, terrain, YlOrRd_r, Set2_r, winter_r, PuBu, RdGy_r, spectral, flag_r, jet_r, RdPu_r, Purples_r, gist_yarg, BuGn, Paired_r, hsv_r, bwr, cubehelix, YlOrRd, Greens, PRGn, gist_heat, spectral_r, Paired, hsv, Oranges_r, prism_r, Pastel2, Pastel1_r, Pastel1, gray_r, PuRd_r, Spectral_r, gnuplot2_r, BuPu, YlGnBu_r, copper, gist_earth_r, Set3_r, OrRd, PuBu_r, ocean_r, brg, gnuplot2, jet, bone_r, gist_earth, Oranges, RdYlGn_r, PiYG, CMRmap_r, YlGn, binary_r, gist_gray_r, Accent, BuPu_r, gist_gray, flag, seismic_r, RdBu_r, BrBG, Reds, BuGn_r, summer_r, GnBu_r, BrBG_r, Reds_r, RdGy, PuRd, Accent_r, Blues, Greys, autumn, cubehelix_r, nipy_spectral_r, PRGn_r, Greys_r, pink, binary, winter, gnuplot, RdBu, prism, YlOrBr, coolwarm_r, rainbow_r, rainbow, PiYG_r, YlGn_r, Blues_r, YlOrBr_r, seismic, Purples, bwr_r, autumn_r, ocean, Set1_r, PuOr, PuBuGn, nipy_spectral, afmhot

Combining Plots in Sage

Just use addition.

g = plot(sin(x), (x, 0,2*pi)) + circle((pi,0), 1, color='red', thickness=3)