Ask Your Question
2

Creating a semilogx (or semilogy or loglog) plot

asked 2011-11-20 12:05:20 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I would like to create a semilogx plot of some data. I have two lists of data and would like to use something like list_plot() to visualize the data, but the x-axis should be logarithmic. I have attempted (and failed) in using pyplot, but get an error message like this:

Your currently selected backend, 'agg' does not support show().
Please select a GUI backend in your matplotlibrc file

which I don't understand. Is there an option to plot() and/or list_plot() that allows one to choose logarithmic axes?

Thanks.

edit retag flag offensive close merge delete

Comments

Thanks to Benjamin Jones. This answer was very helpful and I was able to produce the figure I needed!

Ed Scheinerman gravatar imageEd Scheinerman ( 2011-11-21 04:13:16 -0600 )edit

@Ed Scheinerman: if the answer helped, you should click the button to "accept the answer". This helps us keep track of unanswered questions and gives him some extra karma to boot. :-)

DSM gravatar imageDSM ( 2011-11-21 04:56:01 -0600 )edit

@DSM: Except that someone community wiki'ed it, so it won't ;-)

kcrisman gravatar imagekcrisman ( 2011-11-21 09:46:14 -0600 )edit

@kcrisman-- ah, the unintended consequence of generosity..

DSM gravatar imageDSM ( 2011-11-21 10:48:02 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
4

answered 2011-11-20 13:31:25 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

The easiest thing to do right now is follow Niles' advice in this question:

How do I create a log plot

Basically, apply the logarithm to your data explicitly and list plot that. You can also change the way ticks are displayed on the axes to make it clear that it's a log plot.

Regarding pyplot, you can still use it but since it is a matplotlib module, the Sage wrappers are not in place to take it's output and display it to you through Sage (unless you do some tweaking to the matplotlib package that ships with Sage --someone correct me if I'm wrong here).

What you can do is call pyplot and have the image saved to a file and view it yourself, e.g.:

# stolen from: http://matplotlib.sourceforge.net/examples/pylab_examples/log_demo.html
import numpy as np
import matplotlib.pyplot as plt

plt.subplots_adjust(hspace=0.4)
t = np.arange(0.01, 20.0, 0.01)

# log x and y axis
plt.subplot(111)
plt.loglog(t, 20*np.exp(-t/10.0), basex=10)
plt.grid(True)
plt.title('loglog base 10 on x')
plt.savefig('foo.png')

If I execute this code in the Sage notebook, I see a nice log plot. In command line Sage, you would get a file saved to disk.

edit flag offensive delete link more
0

answered 2011-11-21 09:44:39 -0600

kcrisman gravatar image

This is not an answer, so don't upvote it - but just for reference, doing a better job with this is Ticket 4529.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-11-20 12:05:20 -0600

Seen: 1,114 times

Last updated: Nov 21 '11