【发布时间】:2018-04-18 07:16:50
【问题描述】:
我完全是wxpython的新手。下面的代码展示了一个简单的情节:
#-*-coding:utf-8-*-
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from matplotlib.offsetbox import AnnotationBbox,OffsetImage
from PIL import Image
fig=plt.figure(figsize=(20,10))
ax = plt.axes(projection=ccrs.PlateCarree())
ax.coastlines()
ax.stock_img()
gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
linewidth=2, color='gray', alpha=15, linestyle='--')
gl.xlabels_top = False
gl.ylabels_left = False
gl.xlines = False
gl.xlocator = mticker.FixedLocator([-180, -45, 0, 45, 180])
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
gl.xlabel_style = {'size': 15, 'color': 'gray'}
gl.xlabel_style = {'color': 'red', 'weight': 'bold'}
img=Image.open(r'E:\python_file\untitled\p.png')
imagebox=OffsetImage(img,zoom=0.05)
imagebox.image.axes=ax
ab=AnnotationBbox(imagebox,[55,10],pad=0,frameon=False)
ax.add_artist(ab)
plt.show()
我试着让它在wxpython中显示,但是不行我试过了。
#-*-coding:utf-8-*-
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
from matplotlib.offsetbox import AnnotationBbox,OffsetImage
from PIL import Image
import wx
class Canvas(wx.Panel):
def __init__(self,parent):
self.fig=plt.figure(figsize=(20,10))
self.ax = plt.axes(projection=ccrs.PlateCarree())
self.ax.coastlines()
self.ax.stock_img()
self.gl = self.ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
linewidth=2, color='gray', alpha=15, linestyle='--')
self.gl.xlabels_top = False
self.gl.ylabels_left = False
self.gl.xlines = False
self.gl.xlocator = mticker.FixedLocator([-180, -45, 0, 45, 180])
self.gl.xformatter = LONGITUDE_FORMATTER
self.gl.yformatter = LATITUDE_FORMATTER
self.gl.xlabel_style = {'size': 15, 'color': 'gray'}
self.gl.xlabel_style = {'color': 'red', 'weight': 'bold'}
def draw(self):
img=Image.open(r'E:\python_file\untitled\p.png')
imagebox=OffsetImage(img,zoom=0.05)
imagebox.image.axes=self.ax
ab=AnnotationBbox(imagebox,[55,10],pad=0,frameon=False)
self.ax.add_artist(ab)
if __name__ == "__main__":
app = wx.App()
fr = wx.Frame(None, title='test')
panel = Canvas(fr)
panel.draw()
fr.Show()
app.MainLoop()
【问题讨论】:
标签: python matplotlib wxpython cartopy