一つは、カスタムものと方法を置き換えることによりステータスバーメッセージ
![enter image description here](https://i.stack.imgur.com/z48iZ.png)
のx
とy
座標一部を変更するax.format_coord
を使用することができ
def format_coord(x,y):
return "text_string_made_from({:.2f},{:.2f})".format(x,y)
ax.format_coord=format_coord
![enter image description here](https://i.stack.imgur.com/oDqgM.png)
残念ながら、角括弧内のデータ値はax.format_coord
ではなく、代わりにナビゲーションツールバーのmouse_move
メソッドによって設定されます。 それを悪化させるのは、mouse_move
が別のメソッド.set_message
を実際に表示するクラスメソッドであることです。ツールバーはバックエンド依存であるため、単純に置き換えることはできません。
代わりに、ツールバーのインスタンスがクラスメソッドの最初の引数として与えられるように、それを猿で修正する必要があります。これにより、ソリューションが少し面倒になります。
以下では、表示するメッセージを設定する関数mouse_move
があります。これは、通常のx
& y
座標format_coord
からです。ツールバーのインスタンスを引数として取り、ツールバーの.set_message
メソッドを呼び出します。ツールバーインスタンスを引数としてmouse_move
関数を呼び出す別の関数mouse_move_patch
を使用します。 mouse_move_patch
関数は 'motion_notify_event'に接続されています。
import numpy as np
import matplotlib.pyplot as plt
def mouse_move(self,event):
if event.inaxes and event.inaxes.get_navigate():
s = event.inaxes.format_coord(event.xdata, event.ydata)
self.set_message(s)
class test():
def __init__(self):
fig=plt.figure()
ax=fig.add_subplot(111)
ax.imshow(np.random.rand(20,20))
def format_coord(x,y):
return "text_string_made_from({:.2f},{:.2f})".format(x,y)
ax.format_coord=format_coord
mouse_move_patch = lambda arg: mouse_move(fig.canvas.toolbar, arg)
fig.canvas.toolbar._idDrag = fig.canvas.mpl_connect(
'motion_notify_event', mouse_move_patch)
t = test()
plt.show()
これは
![enter image description here](https://i.stack.imgur.com/4NWGI.png)
は、それがどのように見えるおよび/またはどのようにそれが – Murmel