# generate_plot_points for multiple variable functions and contour_plot

Is there a default sage function to generate all (x,y,f(x,y)) values the program uses to draw a multivariable function or the contours of let's say a f(x,y)=C ? I am new to sage and could only find that generate_plot_points works only for one variable functions.

Example from documentation:

sage: from sage.plot.plot import generate_plot_points
sage: generate_plot_points(sin, (0, pi), plot_points=2, adaptive_recursion=0)


I guess one could solve symbolically let's say a contour equation and then create the values i talk about like discussed here:

sage: var('x,y')
(x, y)
sage: solve(y^2 - x^3 - x == 0, [y])
[y == -sqrt(x)*sqrt(x^2 + 1), y == sqrt(x)*sqrt(x^2 + 1)]


then just plot each of those two above and combine them. But this could become really cumbersome since one could have a terribly complicated equation. So can this be done currently or someone needs a workaround to achieve this? excuse my english :)

edit retag close merge delete

Sort by » oldest newest most voted

The function you are looking for is contour_plot. The following works:

var("y")
contour_plot( y^2 - x^3 - x == 0, (x,-5,5), (y,-5,5), fill=False, axes=true )

more

I believe the OP is asking how to acquire the specific *points* Sage (really, matplotlib, in this case) uses, though, not to do the plotting. I'm not sure mpl really thinks that way about its plots, though.

I'm not sure how easy this is. The problem is that Sage doesn't actually do anything with this until it's requested to be shown as a figure.

The magic is done by contourf in matplotlib. You may find this question or this one helpful, though no guarantees. You can create a Matplotlib object from a Sage one by doing something C = implicit_plot(...) and then c = C.matplotlib(). But you'd still have to extract stuff from it and I'm not an mpl expert, here one exits Sage territory since mpl thinks differently about plots - data, not functions.

more
{"ft_lang_label":"__label__en","ft_lang_prob":0.82502145,"math_prob":0.9711021,"size":987,"snap":"2023-40-2023-50","text_gpt3_token_len":242,"char_repetition_ratio":0.12207528,"word_repetition_ratio":0.0,"special_character_ratio":0.2563323,"punctuation_ratio":0.13265306,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99770457,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-25T23:34:41Z\",\"WARC-Record-ID\":\"<urn:uuid:ab88885a-b2f8-4239-be0c-bb1bca56745d>\",\"Content-Length\":\"63166\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8aef3101-e789-4329-9407-d0a6f3371fa8>\",\"WARC-Concurrent-To\":\"<urn:uuid:3e11a61c-7f94-4c3c-98d2-61e1eed9a429>\",\"WARC-IP-Address\":\"194.254.163.53\",\"WARC-Target-URI\":\"https://ask.sagemath.org/question/9140/generate_plot_points-for-multiple-variable-functions-and-contour_plot/?answer=23497\",\"WARC-Payload-Digest\":\"sha1:THFHBEPWIAY4DGHW2BRZMHIFKCM6T3QK\",\"WARC-Block-Digest\":\"sha1:2OPQUTMPNMXE432SBOQ5E7YLJKONVJWN\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510100.47_warc_CC-MAIN-20230925215547-20230926005547-00828.warc.gz\"}"}