简体   繁体   中英

How can I maximize my figure on matplotlib python using macOS?

fig, ax = plt.subplots(figsize=(16,8),dpi=100,subplot_kwn {'projection':nccrs.PlateCarree()})
ax.set_global()
plt.subplots_adjust(left=0.04, bottom=0.02, right=0.96, top=0.96)  

# set a figure window's title
fig2 = plt.gcf()
fig2.canvas.set_window_title('Metheoros 1.0')
 mng = plt.get_current_fig_manager()
 mng.Maximize(True)

I Tried this, but didn't work on mac

The first line should have an equals sign in place of the n in subplot_kwn:

fig, ax = plt.subplots(figsize=(16,8),dpi=100,subplot_kw= {'projection':ccrs.PlateCarree()})

You might want to check what you have imported cartopy.crs as, because that may cause problems as well.


EDIT:

So I did quite a bit of digging, and found that in mng has a method called 'full_screen_toggle', so in theory, you could call mng.full_screen_toggle() followed by mng.show() . I tried that, but that seemed to have no effect. I dug through the source code and found that the Mac OS X backend does not have a fullscreen function implemented (as far as I can tell).

That means that you'll have to use a different backend. You can change backends by calling plt.switch_backend('backend') where backend is your desired backend. This function accepts the following arguments:

'pdf', 'pgf', 'Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'

# -*- coding: UTF-8 -*-    
'''
Created on 4 de set de 2016

@author: VladimirCostadeAlencar
'''

from numpy import arange, sin, pi
import matplotlib
matplotlib.use('WXAgg')

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure

import wx

class CanvasPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)
        self.canvas = FigureCanvas(self, 0, self.figure)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)
        self.Fit()


    def draw(self):
        from ler_csv import ler_csv
        from plotar_csv04 import plotar_pontos
        nomearq = 'gps01.csv'  
        print 'Reading points...'
        coords = ler_csv(nomearq)
        figure, ax = plotar_pontos(self, coords)
        print 'Plotting on Wx...'
        self.canvas = FigureCanvas(self, 0, figure)


if __name__ == "__main__":
    app = wx.PySimpleApp()
    fr = wx.Frame(None, title='Metheoros v1.0 - 2016')
    panel = CanvasPanel(fr)
    panel.draw()
    fr.Maximize(True)
    fr.Show()
    app.MainLoop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM