[AstroPy] Histogram problem in astropy tutorial

David Stansby dstansby at gmail.com
Tue Aug 27 10:10:28 EDT 2019


Hi Gordon,

If you're using Matplotlib in a normal python session then you don't need
the '%matplotlib inline' command, but you will need to append 'plt.show()`
to the end of your script to make the figure show up.

Cheers,
David

On Tue, 27 Aug 2019 at 13:13, Gordon Dennis <gordon.b.dennis at gmail.com>
wrote:

> Hi everybody
>
> I'm having some difficulty with the example 'Galaxy mass' in the tutorial
> at
> http://learn.astropy.org/rst-tutorials/quantities.html?highlight=filtertutorials
>
> 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.figure()
>
> plt.hist(v, bins='auto', histtype="step")
>
> plt.ylabel("N")
>
> … 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
>
> [image: Description: analyticalEngine]
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20190827/c84c82ba/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/c84c82ba/attachment-0001.jpg>


More information about the AstroPy mailing list