Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log x-scale in imshow :: matplotlib

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?

like image 411
lovespeed Avatar asked Dec 30 '13 10:12

lovespeed


People also ask

How do I create a log scale in matplotlib?

pyplot library can be used to change the y-axis or x-axis scale to logarithmic respectively. The method yscale() or xscale() takes a single value as a parameter which is the type of conversion of the scale, to convert axes to logarithmic scale we pass the “log” keyword or the matplotlib. scale.

How do you scale Imshow?

Use the extent parameter of imshow to map the image buffer pixel coordinates to a data space coordinate system. Next, set the aspect ratio of the image manually by supplying a value such as "aspect=4" or let it auto-scale by using aspect='auto'. This will prevent stretching of the image.

How do you scale X and Y axis in Python?

To change the range of X and Y axes, we can use xlim() and ylim() methods.


1 Answers

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

like image 111
Paul H Avatar answered Oct 18 '22 23:10

Paul H