[AstroPy] Histogram problem in astropy tutorial

Gordon Dennis gordon.b.dennis at gmail.com
Tue Aug 27 08:13:04 EDT 2019

Hi everybody

I'm having some difficulty with the example 'Galaxy mass' in the tutorial at

These lines are to setup matplotlib:

import matplotlib.pyplot as plt

%matplotlib inline

Spyder will not accept the second (i.e. %matplotlib inline) because,
according to a Stack Overflow answer 'Line magics are only supported by the
IPython command line. They cannot be used inside a script, because
%something is not correct Python syntax'.

Suggestion is to use

exec(%matplotlib inline)

This is accepted by the Python interpreter but doesn't work, i.e. the
subsequent code


plt.hist(v, bins='auto', histtype="step")


. does not produce the histogram expected.  The variable v is calculated
earlier in the code.


All the rest of the code works exactly as expected.  I've added input
statements to vary Reff and vmean in order to observe the effect of varying
these parameters and the results from the code check out against results
using a calculator.

I'm using Spyder 3 on Windows 10, fully patched.

Does anyone know of a way around this histogram problem?

Best regards

Gordon Dennis



+44(0)1934 838096 / +44(0)7774628110 / Skype: gordon.dennis

Sent from my Analytical Engine

Description: analyticalEngine


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20190827/fedc5c21/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.jpg
Type: image/jpeg
Size: 3301 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20190827/fedc5c21/attachment-0001.jpg>

More information about the AstroPy mailing list