matplotlib自定義鼠標光標坐標格式的實現(xiàn)
matplotlib
默認在圖像Windows窗口中顯示當前鼠標光標所在位置的坐標,格式為x=xx, y=xx
。
鼠標光標的坐標格式由子圖模塊Axes
中的format_coord
函數(shù)控制。
通過重寫format_coord
函數(shù)即可實現(xiàn)坐標的自定義格式。
注意:調(diào)用format_coord
函數(shù)的對象是子圖對象,常見的錯誤主要在沒有正確的獲取當前子圖對象。
format_coord
函數(shù)源碼
matplotlib.axes.Axes.format_coord def format_coord(self, x, y): """Return a format string formatting the *x*, *y* coordinates.""" if x is None: xs = '???' else: xs = self.format_xdata(x) if y is None: ys = '???' else: ys = self.format_ydata(y) return 'x=%s y=%s' % (xs, ys)
自定義坐標格式實現(xiàn)
import matplotlib.pyplot as plt def format_coord(x, y): return 'x坐標為%1.4f, y坐標為%1.4f' % (x, y) #獲取當前子圖 ax=plt.gca() ax.format_coord = format_coord plt.show()
到此這篇關(guān)于matplotlib自定義鼠標光標坐標格式的實現(xiàn)的文章就介紹到這了,更多相關(guān)matplotlib自定義鼠標光標坐標內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python實現(xiàn)excel轉(zhuǎn)置問題詳解
這篇文章主要介紹了python實現(xiàn)excel轉(zhuǎn)置問題詳解,excel轉(zhuǎn)置分為兩種情況,一個是較為簡單的只需要行轉(zhuǎn)列,列轉(zhuǎn)行,具體詳解,感興趣的小伙伴可以參考一下2022-09-09Python入門之三角函數(shù)sin()函數(shù)實例詳解
這篇文章主要介紹了Python入門之三角函數(shù)sin()函數(shù)實例詳解,分享了相關(guān)實例,具有一定參考價值,需要的朋友可以了解下。2017-11-11Python實現(xiàn)將橫表和縱表任意轉(zhuǎn)換的兩種方法
在日常做數(shù)據(jù)分析,接收到最多的表格是縱表,每個字段變量都有很長數(shù)據(jù)的長表,我們稱之為縱向數(shù)據(jù),但是,有時候,我們也會遇到橫表,對于橫向數(shù)據(jù),我們會數(shù)據(jù)轉(zhuǎn)化,將其轉(zhuǎn)化為縱向數(shù)據(jù),感興趣的同學跟著小編一起來學習吧2023-12-12