Plotting and the show() method

asked 2012-12-08 18:54:30 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

Hi Wisdom wranglers,

I'm a bit puzzled by the plot2d interface in sage. Using the cli interface, I discovered that I had to use the list_plot().show() method to get the png to show. Here is a slice of the array passed to list_plot():

[(0.000000000000000, -22.605560302734375), (0.108611997882434, -22.714309692382812), (0.219268673499272, -22.81563949584961), (0.331878474116081, -22.90947914123535)]

Without the show() there was no error, but no plot. I'm puzzled because the examples in the plot2d documentation do not indicate that show() is necessary.

Question: when is the show() method necessary for list_plot() or other plot functions?

Note: I am using the cli rather than notebook interface. Perhaps this is the reason. (I simply don't have the bandwidth (or the inclination) to run a notebook server on my tiny computer)

edit retag flag offensive close merge delete


Couple of questions: 1. What is the exact command you are using, and what version of Sage are you using? 2. What output does the command `show_default()` return? Just using something like `sage: list_plot(...)` will work by itself. If you assign your plot to some variable, like `sage: p = list_plot(...)`, it won't work. The actual rendering of the plot happens only when the plot is about to be "printed", that is when the `_repr_` method is called. The command `show_default()` controls what is output when you use the former command. If it is set to `False` then you will still get a text output like `Graphics object consisting of 1 graphics primitive` - do you get this?

ppurka gravatar imageppurka ( 2012-12-08 23:12:06 +0200 )edit

Hi ppurka, 1. The exact command is as follows: list_plot(self.ellipse,axes='true',aspect_ratio='automatic').show() where self.ellipse slice as follows: [[-0.2502810527046193, -0.9528485681543885], [-0.23332252056744662, -0.9570135783421186], [-0.2162905291096238, -0.9608821121646137], [-0.19918932688797977, -0.9644526012140253]...etc] (Note: This is the snippet of source code which requires the show() command.) 1a. I just tested the same source code in the notebook, and the show() is also needed. Omitting the show() and no-show of the ellipse (: 2. show_default() is True When set to False and show() not called, there is no text output of the Graphic i.e. same behaviour as when set to True - need show() 3. My version of sage: Sage Version 5.0.1, Release Date: 2012-06-10 tx!

PatB gravatar imagePatB ( 2012-12-08 23:19:33 +0200 )edit

Can you get something like `list_plot([[1,2],[2,3],[3,4]])` to work? I'm running the same version of Sage on an older MacBook in the command line and list_plot will launch a window with the plot in it.

calc314 gravatar imagecalc314 ( 2012-12-09 00:30:25 +0200 )edit

I can induce the situation you are getting if I cause an error by asking for command line help first. For example, `plot?` causes me to get an error. Then, I cannot get any plots to launch in a window without the show command. This is quite odd. Can you get a simple list plot to launch a window if it is the first line you run after launching Sage?

calc314 gravatar imagecalc314 ( 2012-12-09 00:41:25 +0200 )edit

I can't reproduce this in the version of sage I have (5.5rc0) and I didn't face this problem when I had 5.0 installed. This can mean that it is a problem with that specific version of sage. However, not seeing even text output makes me think that there is something more fundamentally wrong with the installation. The reason why i think so is because the text output is actually doctested and so this errant behavior would have been caught before release.

ppurka gravatar imageppurka ( 2012-12-09 08:29:55 +0200 )edit