logo4 Evolution is progress—                          
progress is creativity.        

Graphics in Sage cells: Matplotlib vs. Sage

In mathematic Sage Cells several programming languages can be used. Most popular, at least by me, are probably python > sage > r. This page discusses and demonstrates the difference between the former two.

Matplotlib is a common python library used throughout this website for generating graphics. It offers an extended graphic library which can be used with sage cell servers.

[Error: Macro 'sagecell' doesn't exist]

The downside is that graphics have to be clicked separately. The link is given below the output cell. This might be acceptable if the graphics will be downloaded and used separate publications but not if the page where it resides is the publication. It is especially cumbersome in simulations.

If you want the the interaction immediatly visible, you have to learn sage. Sage programming language is mostly python as many programs as the one above run with both languages. But some exceptions exist, and those are especially prominent in graphics. Sage uses its own extended graphic library. It ofers a wide range of functionality but some feature as vlines in the example above is missing.

The same graphic as above in pure sage looks like:

[Error: Wrong macro arguments: "sagecell2 lang=\"sage\"" for macro 'sagecell' (maybe wrong macro tag syntax?)]

Tags: Software

Poisson Distribution

Though this article tackles Poisson distribution, a type of discrete probability distribution, it is rather focused on practical questions how to use matplotlib to construct graphs of that distribution.

Numpy offers three parameters that effect graphical appearance:

parameter meaning usage
mu shape parameter essential, to construct a probability distribution
loc origin optional, the origin of the probability distribution default = 0
size vector length optional, size of the one dimensional array of random variables default=0 => no array but a single random variable is returned
[Error: Macro 'mathplot' error: mathplot() got an unexpected keyword argument 'title']

The probability mass function can be written:

[Error: Macro 'me' doesn't exist]

The cumulative probability function can be described by the equation:

[Error: Macro 'me' doesn't exist]

The function of the Numpy parameters can be tested by the following sage cell.

[Error: Macro 'sagecell' doesn't exist]

(c) Mato Nagel, Weißwasser 2004-2023, Disclaimer