Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am in an interesting situation. I have the diagram's image with axis

IMG

So when I try to plot this diagram wiht the next code:

plt.figure("Ti Zr")
ax = plt.subplot(111)
im = plt.imshow(np.flipud(plt.imread('Ti_ZrB.png')), 
    origin='lower', 
    extent=[0, 800, 1000, 32700])
plt.xticks([10,15, 43, 95, 215,542,800])
plt.yticks([1000, 1860, 2670, 8600, 16600,32700])

plt.axis('normal')
plt.show()

Before uploading the image I have just only cut out the axis numbers on Corel. Finaly I have got this

IMG

As you can see the axis has been displaced and they are not in their own place. Usually i use this way to plotting diagrams and before I haven't any problems whit it. But now I haven't any idea. Thank you in advance. I would be so grateful for some help

share|improve this question
3  
Your original has a non-linear axes, it might be logarithmic. To match the ticks, you need to figure out what the function is. – tcaswell Feb 3 at 17:39
So how I can understood the one way only it is find the function? – Protoss Reed Feb 4 at 15:16
plot the pixel positions of the ticks vs the number on them and try to guess the from. – tcaswell Feb 4 at 15:50

1 Answer

up vote 2 down vote accepted

You can use mouse-click events in matplotlib to easily determine the coordinates of the ticks instead of guessing it.

import numpy as np
import matplotlib.pyplot as plt

def tell_click_coordinates(event):
    print "X: %.0f, Y: %.0f" % (event.xdata, event.ydata)

fig = plt.figure("Ti Zr")
fig.canvas.mpl_connect("button_press_event", tell_click_coordinates)

ax = plt.subplot(111)
im = plt.imshow(np.flipud(plt.imread('14675002_in.png')), 
    origin='lower', 
    extent=[0, 800, 1000, 32700])
plt.xticks([10,15, 43, 95, 215,542,800])
plt.yticks([1000, 1860, 2670, 8600, 16600,32700])

plt.axis('normal')
plt.show()

Clicking one tick after the other will give you:

X: 6, Y: 1576
X: 6, Y: 6902
X: 10, Y: 13037
X: 8, Y: 20415
X: 11, Y: 26383
X: 76, Y: 2177
X: 260, Y: 1846
X: 494, Y: 1846
X: 594, Y: 1680
X: 715, Y: 1928

Then, you can adjust your plot with these values:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure("Ti Zr")

ax = plt.subplot(111)
im = plt.imshow(np.flipud(plt.imread('14675002_in.png')), 
    origin='lower', 
    extent=[0, 800, 1000, 32700])
plt.xticks([76,260,494,594,715,800],[10,15, 43, 95, 215,542,800])
plt.yticks([1576,6902, 13037, 20415, 26383, 32700],[1000, 1860, 2670, 8600, 16600,32700])

plt.axis('normal')
plt.show()

and you get

result

share|improve this answer
Thank you very much! This is really useful, all what I need ) – Protoss Reed Feb 5 at 14:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.