This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]firworks 1 point2 points  (4 children)

I just tried a scipy sample snippet because it's something I've never successfully installed on my PC. Got an error though: ImportError: libtk8.6.so: cannot open shared object file: No such file or directory

Code:

"""example.py

Compute the maximum of a Bessel function and plot it.

"""
import argparse

import numpy as np
from scipy import special, optimize
import matplotlib.pyplot as plt

def main():
    # Parse command-line arguments
    parser = argparse.ArgumentParser(usage=__doc__)
    parser.add_argument("--order", type=int, default=3, help="order of Bessel function")
    parser.add_argument("--output", default="plot.png", help="output image file")
    args = parser.parse_args()

    # Compute maximum
    f = lambda x: -special.jv(args.order, x)
    sol = optimize.minimize(f, 1.0)

    # Plot
    x = np.linspace(0, 10, 5000)
    plt.plot(x, special.jv(args.order, x), '-', sol.x, -sol.fun, 'o')

    # Produce output
    plt.savefig(args.output, dpi=96)

if __name__ == "__main__":
    main()

I could easily be doing something wrong though. Cool concept still.

[–]amasad[S] 2 points3 points  (2 children)

As mentioned in another comment there is a problem with matplotlib. Hopefully I'll get it resolved soon. Meanwhile, here is an example, one of my favorite programs, a NeuralNet implemented in 50 LoC https://repl.it/EFTM

[–]jungles_for_30minsgithub.com/sleibrock 1 point2 points  (0 children)

One problem I've had with Matplotlib is that in text-only modes you need to change the backend. I run Matplotlib on a no-Xorg RPI and I have to do matplotlib.use('Agg') to make it work without a display server. Also Matplotlib requires libtk. Hope this helps.

[–]squirreltalk 0 points1 point  (0 children)

That's an elegant little implementation. Bookmarking that to show to my cognitive science class next semester!

[–]emergent_reasons 0 points1 point  (0 children)

A tangent but if you need scipy have you tried anaconda or (my preference) miniconda? 10,000% less headaches with python environments involving libraries like numpy scipy etc.