Create a gist now

Instantly share code, notes, and snippets.

@glamp /log_func.py
Last active Nov 20, 2017

Embed
What would you like to do?
import numpy as np
import pylab as pl
x = np.random.uniform(1, 100, 1000)
y = np.log(x) + np.random.normal(0, .3, 1000)
pl.scatter(x, y, s=1, label="log(x) with noise")
pl.plot(np.arange(1, 100), np.log(np.arange(1, 100)), c="b", label="log(x) true function")
pl.xlabel("x")
pl.ylabel("f(x) = log(x)")
pl.legend(loc="best")
pl.title("A Basic Log Function")
pl.show()
@billsmithaustin

This comment has been minimized.

Show comment
Hide comment
@billsmithaustin

billsmithaustin Jun 19, 2013

Thank you for offering this. To help beginners, you could add a call to pl.show() at the end.

Thank you for offering this. To help beginners, you could add a call to pl.show() at the end.

@gogosanka

This comment has been minimized.

Show comment
Hide comment
@gogosanka

gogosanka Oct 24, 2014

Thank you for this tutorial! I agree, for beginners, a pl.show() at the end would have saved me some time and confusion wondering how to actually show the graph we built with your code.

Thank you for this tutorial! I agree, for beginners, a pl.show() at the end would have saved me some time and confusion wondering how to actually show the graph we built with your code.

@Chuck-UGA

This comment has been minimized.

Show comment
Hide comment
@Chuck-UGA

Chuck-UGA Feb 5, 2015

Thanks for tutorial!

Thanks for tutorial!

@mkcor

This comment has been minimized.

Show comment
Hide comment
@mkcor

mkcor Nov 10, 2016

Hi!

Thanks for all the nice blog posts.

I'm surprised you still import pylab. This practice is no longer recommended, as you can read here :
http://matplotlib.org/faq/usage_faq.html#matplotlib-pyplot-and-pylab-how-are-they-related

Best,
Marianne

PS: This http://blog.yhat.com/posts/python-random-forest.html took me here, and it was posted on November 7, 2016.

mkcor commented Nov 10, 2016

Hi!

Thanks for all the nice blog posts.

I'm surprised you still import pylab. This practice is no longer recommended, as you can read here :
http://matplotlib.org/faq/usage_faq.html#matplotlib-pyplot-and-pylab-how-are-they-related

Best,
Marianne

PS: This http://blog.yhat.com/posts/python-random-forest.html took me here, and it was posted on November 7, 2016.

@maomaochonghuang

This comment has been minimized.

Show comment
Hide comment
@maomaochonghuang

maomaochonghuang Jan 15, 2017

Thank you for your simple and excellent example

Thank you for your simple and excellent example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment