[AstroPy] Histogram problem in astropy tutorial

Wilfred Tyler Gee wtylergee at gmail.com
Tue Aug 27 16:17:37 EDT 2019


Hi Gordon,

Just to be clear, this is not a problem with the histogram but with the
environment and how it is being called. Spyder is a different environment
from a jupyter notebook and the tutorial is specifically using a notebook.

That said, Spyder does (I believe) have a mechanism for plotting within the
IDE itself. Most likely you just remove the line about the  matplotlib
magic.

Cheers,

On Wed, Aug 28, 2019, 00:11 David Stansby <dstansby at gmail.com> wrote:

> 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
>>
> _______________________________________________
> 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/20190828/f40b2c98/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/20190828/f40b2c98/attachment.jpg>


More information about the AstroPy mailing list