Ask Your Question
2

Creating a semilogx (or semilogy or loglog) plot

asked 2011-11-20 19:05:20 +0100

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 11:13:16 +0100 )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 11:56:01 +0100 )edit

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

kcrisman gravatar imagekcrisman ( 2011-11-21 16:46:14 +0100 )edit

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

DSM gravatar imageDSM ( 2011-11-21 17:48:02 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2011-11-20 20:31:25 +0100

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 16:44:39 +0100

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 19:05:20 +0100

Seen: 2,128 times

Last updated: Nov 21 '11