6

I have a table which looks like this

enter image description here

I have the highlighted part as a matrix of which I want to do an imshow. I want to have the x-scale of the plot logarithmic, as one can understand by looking at the parameter values in the topmost row. How to do this is matplotlib?

lovespeed
  • 4,835
  • 15
  • 41
  • 54
  • You **cannot** apply `log` scale on an image. It does not make any sense. `imshow` gets an array in a sense every value is a pixel value. So in your image (i.e., your table) 67 is just a pixel to which 64 is the next. It does not care to your scaling concept. – Developer Dec 30 '13 at 11:37
  • @Developer it may not make sense for pure image analysis *per se*, but three dimensional data, displayed as an image, can have logarithmic scales. For this `pcolor` is appropriate per my answer. – Paul H Dec 30 '13 at 17:46
  • @PaulH The confusing part is that SO says a `matrix`. Your `pcolor` solution is great however in which you're assigning coordinates for every cell! In *Excel 2007+* one may easily colorise the matrix (conditional formatting) but the concept and usage here is still not clear. – Developer Dec 31 '13 at 06:45
  • possible duplicate of [Non-linear axes for imshow in matplotlib](http://stackoverflow.com/questions/11488800/non-linear-axes-for-imshow-in-matplotlib) – tacaswell Dec 31 '13 at 16:34
  • @Developer: I understand that a `log` scale in `imshow` does not make sense as it is a pixel by pixel representation of a matrix. But what I want to show by the color is a quantity which depends on two variables `x` and `y` and I have values of this quantity for `x=10,100,1000` and so on, so I need to make the x-scale of the density plot logarithmic. @PaulH: Thanks for the answer – lovespeed Jan 01 '14 at 16:37

1 Answers1

16

You want to use pcolor, not imshow. Here's an example:

import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
Z = np.random.random(size=(7,7))
x = 10.0 ** np.arange(-2, 5)
y = 10.0 ** np.arange(-4, 3)
ax.set_yscale('log')
ax.set_xscale('log')
ax.pcolor(x, y, Z)

Which give me:

log pcolor

Paul H
  • 65,268
  • 20
  • 159
  • 136