How do I draw a grid onto a plot in Python?

前端 未结 5 965
挽巷
挽巷 2020-12-04 06:06

I just finished writing code to make a plot using pylab in Python and now I would like to superimpose a grid of 10x10 onto the scatter plot. How do I do that?

My cur

5条回答
  •  暖寄归人
    2020-12-04 06:37

    Here is a small example how to add a matplotlib grid in Gtk3 with Python 2 (not working in Python 3):

    #!/usr/bin/env python
    #-*- coding: utf-8 -*-
    
    import gi
    gi.require_version('Gtk', '3.0')
    from gi.repository import Gtk
    from matplotlib.figure import Figure
    from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas
    
    win = Gtk.Window()
    win.connect("delete-event", Gtk.main_quit)
    win.set_title("Embedding in GTK3")
    
    f = Figure(figsize=(1, 1), dpi=100)
    ax = f.add_subplot(111)
    ax.grid()
    
    canvas = FigureCanvas(f)
    canvas.set_size_request(400, 400)
    win.add(canvas)
    
    win.show_all()
    Gtk.main()
    

提交回复
热议问题