I'm writing a program that obtains plot data from a graph(JPEG). Vertical axis is logarithmic. I successfully made a program that understands horizontal and vertical axes as linear (not logarithmic), see the code below:
%matplotlib inline
from PIL import Image
from scipy import *
from pylab import *
im = array(Image.open('fig1.jpg'))
hh = im.shape[0]
ww = im.shape[2]
imshow(im)
print(im[100,0,:])
Col = array([255,0,0])#赤
bnd = 30
yax = linspace(0.5,2e-4,hh)
xax = linspace(1,14,ww)
for i in range(hh):
for j in range(ww):
im[i,j,:] = 255*(any(im[i,j,:]>Col+bnd) or any(im[i,j,:]<Col-bnd))
mapim = abs(im[:,:,0]/255-1).astype(bool)
yval = array([average(yax[mapim[:,t]]) for t in range(ww)])
rlt = interp(range(100),xax,yval)
I have no idea how to modify it to make it understand logarithmic axis. Please help me.
You just need to convert the y max and min to log scale:
ymax_lin = log10(0.5)
ymin_lin = log10(2e-4)
yax = linspace(ymax_lin,ymin_lin,hh)
and convert back to linear the yval
values at the end:
yval = 10**yval
The full working code is here:
%matplotlib inline
from PIL import Image
from scipy import *
from pylab import *
im = array(Image.open('fig1.jpg'))
hh = im.shape[0]
ww = im.shape[1]
imshow(im)
print(im[100,0,:])
Col = array([255,0,0])
bnd = 30
ymax_lin = log10(0.5)
ymin_lin = log10(2e-4)
yax = linspace(ymax_lin,ymin_lin,hh)
xax = linspace(1,14,ww)
for i in range(hh):
for j in range(ww):
im[i,j,:] = 255*(any(im[i,j,:]>Col+bnd) or any(im[i,j,:]<Col-bnd))
mapim = abs(im[:,:,0]/255-1).astype(bool)
yval = array([average(yax[mapim[:,t]]) for t in range(ww)])
yval = 10**yval
rlt = interp(range(100),xax,yval)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With