Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can I do gr_edit "quietly"?

    Hi all,

    Whenever I use `gr_edit` to manipulate a graph, the graph window enters an editing mode and "flashes". When I execute multiple `gr_edit` commands at once, this flashing is not very elegant (it will flash quite a few times very quickly...).

    I am wondering if it is possible to suppress the window operations of `gr_edit` to avoid this flashing of the window (but still edit the graph as I wanted)?

    Kind regards,
    Hall

  • #2
    Since gr_edit is undocumented, this is (likely, without testing it myself) a good question for StataCorp. Perhaps Hua Peng (StataCorp) or Thomas Stringham (StataCorp) have thoughts on this.

    Comment


    • #3
      While I don't have any example code to test this myself, I think you would have to run your code in batch (headless) mode. For example: https://www.stata.com/support/faqs/windows/batch-mode/

      Comment


      • #4
        If you look inside gr_edit.ado you see that it draws the graph after each edit, resulting in the flicker. You also see that the changing of the graph is done with the command _gm_edit . So if you create your initial graph with the nodraw option, do the edits with _gm_edit and finish with graph display, then your graph window will appear only once with the final graph:

        Code:
        sysuse auto
        scatter price mpg, nodraw name(foo)
        _gm_edit .foo.plotregion1.plot1.style.editstyle marker(fillcolor(stred)) editcopy
        _gm_edit .foo.plotregion1.plot1.style.editstyle marker(linestyle(color(stred))) editcopy
        graph display foo
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Alternatively, replace gr_edit with .Graph, then ask for the graph to be drawn after the edits. The ensuing example is taken from #4: https://www.statalist.org/forums/for...ndividual-bars.

          Compare:

          Code:
          sysuse citytemp, clear
          estimates clear
          eststo m1: regress tempjan tempjuly i.region cooldd
          margins, over(region) atmeans
          marginsplot, recast(bar)
          
          local colors red blue orange yellow
          forval j= 1/`=wordcount("`colors'")'{
              gr_edit .plotregion1.plot1.EditCustomStyle , j(`j') style(area(shadestyle(color(`=word("`colors'", `j')'%70))))
          }
          to

          Code:
          sysuse citytemp, clear
          estimates clear
          eststo m1: regress tempjan tempjuly i.region cooldd
          margins, over(region) atmeans
          marginsplot, recast(bar)
          
          local colors red blue orange yellow
          forval j= 1/`=wordcount("`colors'")'{
              .Graph.plotregion1.plot1.EditCustomStyle , j(`j') style(area(shadestyle(color(`=word("`colors'", `j')'%70))))
          }
          .Graph.drawgraph

          Comment


          • #6
            .Graph is just the name of the graph, and Graph is the default name for a graph if you don't specify the name() option. So in the example I gave you would use .foo .

            The difference between _gm_edit and directly modifying the graph with .<name of graph> is that _gm_edit logs the changes you made. So if you save the graph as a Stata graph (.gph), the changes you made by direct editing will not be saved, but changes you made with _gm_edit will be saved.

            Code:
            clear all
            sysuse auto
            scatter price mpg, nodraw name(bar)
            .bar.plotregion1.plot1.style.editstyle marker(fillcolor(stred)) editcopy
            graph display
            graph save "bar" "C:\temp\Graph.gph", replace
            graph use  C:\temp\Graph.gph
            
            scatter price mpg, name(foo, replace) nodraw
            _gm_edit .foo.plotregion1.plot1.style.editstyle marker(fillcolor(stred)) editcopy
            graph display foo
            graph save "foo" "C:\temp\Graph.gph", replace
            graph use  C:\temp\Graph.gph

            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              Thanks! Maarten Buis and Andrew Musau.
              Both _gm_edit and .Graph works fine for me.

              Comment

              Working...
              X