[AstroPy] Histogram problem in astropy tutorial

Lingyi Hu hulingyi1995 at yahoo.com.sg
Tue Aug 27 09:55:36 EDT 2019


Hi Gordon,

I believe you can do a normal plt.show() at the end of plotting to show the
graph. Don't think you need the exec(%matplotlib inline) if you are not in
ipython. I don't use Spyder but apparently there are some settings you can
set in Spyder to make it work like a IPython notebook:
https://stackoverflow.com/questions/23585126/how-do-i-get-interactive-plots-again-in-spyder-ipython-matplotlib

Lingyi

On Tue, Aug 27, 2019 at 8:13 PM 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/32bd9a09/attachment.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/32bd9a09/attachment.jpg>


More information about the AstroPy mailing list