Ask Your Question

Creating a semilogx (or semilogy or loglog) plot

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

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?


edit retag flag offensive close merge delete


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 -0500 )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 -0500 )edit

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

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

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

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

2 answers

Sort by ยป oldest newest most voted

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

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:
import numpy as np
import matplotlib.pyplot as plt

t = np.arange(0.01, 20.0, 0.01)

# log x and y axis
plt.loglog(t, 20*np.exp(-t/10.0), basex=10)
plt.title('loglog base 10 on x')

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

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

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


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

Seen: 1,029 times

Last updated: Nov 21 '11