Announcement

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

  • Smaller and low quality graphs in Stata 17

    Dear community,

    I'm using Stata 17 SE and getting smaller and low-quality graphs than in previous versions. This seems to be pervasive and happens with the default settings of Stata 17. Do you experience the same?



    Thanks,

  • #2
    Myself, not really, Emanuel.
    But, I always set the width and height of my graph export at rather large values and next resize it (smaller) in my reports as to get it printed at a 'high resolution' in the document.
    Using this example:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte ID float(beta alpha) str11 country byte developed float group_median
    23 1.8362274 -.54704875 "Hungary" 0 .6501096
    9 .4778549 .10170976 "China" 0 .6501096
    37 1.2196035 -.498645 "Mexico" 0 .6501096
    42 -.58203423 .29589716 "Philippines" 0 .6501096
    36 -.0781569 .04942717 "Malaysia" 0 .6501096
    46 1.1002984 -.7458544 "SA" 0 .6501096
    45 -.9582992 .50124466 "Russia" 0 .6501096
    47 .004715125 .01044181 "Saudi" 0 .6501096
    22 .337076 -.01110824 "HK" 0 .6501096
    26 .963553 -.6590986 "Indonesia" 0 .6501096
    8 -.8042764 .3144665 "Chile" 0 .6501096
    32 .8671937 -.03975229 "Kuwait" 0 .6501096
    10 -.4385346 .3023163 "Colombia" 0 .6501096
    5 .9690037 -.4535788 "Brazil" 0 .6501096
    15 .7705156 .0395709 "Egypt" 0 .6501096
    12 .52970374 .09511489 "Czech" 0 .6501096
    41 .9279866 .05789427 "Peru" 0 .6501096
    25 .9379643 -.22651567 "India" 0 .6501096
    48 .6910229 .1001157 "Singapore" 1 .9087965
    44 .4672258 -.18966088 "Portugal" 1 .9087965
    59 .9863901 1.3020502 "UK" 1 .9087965
    4 1.462029 .006443781 "Belgium" 1 .9087965
    2 .3531039 .14569756 "Australia" 1 .9087965
    20 1.7001376 .27322334 "Germany" 1 .9087965
    29 .7537184 -.15440215 "Italy" 1 .9087965
    21 -.10167068 .2361137 "Greece" 1 .9087965
    30 .9087965 .19136943 "Japan" 1 .9087965
    3 2.0533354 .26389042 "Austria" 1 .9087965
    53 1.742693 .3639724 "Switzerland" 1 .9087965
    54 .4521819 -.10904413 "Taiwan" 1 .9087965
    39 1.5855486 -.1498644 "Norway" 1 .9087965
    31 1.3172716 .05321888 "Korea" 1 .9087965
    7 1.2979743 -.07605615 "Canada" 1 .9087965
    27 .9888381 .8458133 "Ireland" 1 .9087965
    52 -.099385 .02396096 "Sweden" 1 .9087965
    40 .9744889 .1189683 "NZ" 1 .9087965
    19 .7592626 -.03824935 "France" 1 .9087965
    51 .19100054 .1868916 "Spain" 1 .9087965
    43 -.03935108 .3513617 "Poland" 1 .9087965
    }
    
    twoway scatter beta alpha, title("Regression Tests of UIP") mlabel(ID) || lfit beta alpha, ytitle(Beta) legend(lab(1 "Beta"))
    graph export "Scatter_lfit_Example.png", width(2600) height(1720) replace
    Of course, you have to decide which multiplication of the graph size (ratio) suits your purpose.
    http://publicationslist.org/eric.melse

    Comment


    • #3
      Thanks ericmelse, that is an interesting example. I have barely used the -width(), height()- options in -graph export-. I will try them. Good choice for making our graphs worth seeing!

      I'm am still not understanding why I get graphs of different sizes in Stata 16 and 17. I'm using the version for Mac and have confirmed that the settings for graphs (in the graph preferences menu) are the same in both versions.

      For example,

      . sysuse auto, clear
      . graph bar price, over(rep78)

      gives me a graph of 158 KB in Stata 16, and another of 16 KB in Stata 17. I'm attaching these two files. The problem is independent of the extension of the file: .gph, .png., .jpg, etc.

      Click image for larger version

Name:	bar16.png
Views:	1
Size:	154.1 KB
ID:	1611354


      Attached Files

      Comment


      • #4
        Please show the command that you're using to export the graph.

        If you export a graph to bitmap format, Stata uses the graph image that's displayed on the screen to export the graph unless you use the -width()- and/or -height()- options. I recommend using just the width or height option and let Stata figure out the other dimension.

        The width and height options are in pixels so if you specify 480 for the height of the example graphs above, you will get an image that's 660 pixels wide and 480 pixels high. However, if you don't use the width or height options, Stata just exports the image on the screen at whatever size it's currently displayed at. If you're on a Mac with a Retina display, your graph that's displayed on the Retina display will be outputted as a high DPI image with double the resolution (144 DPI). If you're using an external monitor that doesn't have a high DPI display, then the exported image will be at the normal 72 DPI.

        Have you updated Stata 16? There was a bug in Stata 16 for Mac where graphs that were exported to bitmap format using the width and/or height options outputted the graphs at twice the resolution they were supposed to on a Retina display.
        -Chinh Nguyen

        Comment


        • #5
          Thanks for the reply Chinh Nguyen (StataCorp).

          It seems that the difference happens previously to exporting the graphs. For example, I run the following lines and get quite different files in Stata 16 or 17:

          . sysuse auto, clear
          . graph bar price, over(rep78)
          . graph export bar.png, replace

          As I explained, the difference in size and quality persist if I use another file extension.

          I have both Stata 16 and 17 up to date. The problem arose with Stata 17 and I thought there would be something to set up. I'm on a Mac that doesn't have the Retina display and I'm not using an external monitor.

          Best,

          Comment


          • #6
            I have confirmed the different behavior between Stata 16 and Stata 17 and I'm investigating why they're different. Stata actually uses macOS's native bitmap export functions for exporting graphs to formats such as PNG, TIFF, and JPG. I know there was a problem with the high DPI bitmap files macOS was producing for Stata 16 in that -putdocx- couldn't handle the 16-bit image that was produced. I don't recall if it's an issue with the docx format requiring 8-bit images and I'm trying to determine if that's still an issue. It's not that Stata 17 is producing low quality bitmap exports--they're now being outputted at the same resolution that bitmaps are exported in Windows and Unix. It's that versions of Stata for Mac prior to Stata 17 allowed macOS to export the bitmaps at whatever resolution it wanted to and Stata 17 is no longer doing that. I'm trying to figure out the reasoning for it.
            -Chinh Nguyen

            Comment


            • #7
              This has been fixed and will be available in a future update.
              -Chinh Nguyen

              Comment


              • #8
                Hi,
                I have a similar problem with Stata 17 in MAC. I couldn't resolve it.
                Labels and titles are smaller than previous versions and they appear in a wrong position. I would really appreciate any help.

                The command:
                twoway ( scatter Automation country2 ) , ///
                xtitle("Country") ytitle("Automation") xscale(r(1(1)8)) xlabel(1(1)8, labsize(medium) nogrid valuelabel) title(Automation by Country)

                Click image for larger version

Name:	Screen Shot 2022-05-09 at 9.07.05 PM.png
Views:	1
Size:	30.2 KB
ID:	1663734

                Comment


                • #9
                  Originally posted by Chinh Nguyen (StataCorp) View Post
                  This has been fixed and will be available in a future update.
                  Has there been any progress made on this? For example I have the latest version of STATA 17, Current update level: 28 Jul 2022, and am working on Mac OS with the M1 pro Apple Silicon, and the problem still persists, and is worse that the previous comments describe. The formatting is unresponsive.

                  E.g. the following command

                  sysuse auto, clear
                  scatter price mpg, title("Good Title: Large", size(large)) name(g1)

                  produces the first graph attached.




                  While the following command,

                  sysuse auto, clear
                  scatter price mpg, title("Good Title: Small", size(small)) name(g2)

                  produces the second graph.



                  Can anyone please shed any light on whether this can be fixed currently? Or when an update is due?
                  Attached Files
                  Last edited by Joe Emmens; 10 Aug 2022, 06:25.

                  Comment


                  • #10
                    Originally posted by Joe Emmens View Post

                    Has there been any progress made on this? For example I have the latest version of STATA 17, Current update level: 28 Jul 2022, and am working on Mac OS with the M1 pro Apple Silicon, and the problem still persists, and is worse that the previous comments describe. The formatting is unresponsive.

                    E.g. the following command

                    sysuse auto, clear
                    scatter price mpg, title("Good Title: Large", size(large)) name(g1)

                    produces the first graph attached.




                    While the following command,

                    sysuse auto, clear
                    scatter price mpg, title("Good Title: Small", size(small)) name(g2)

                    produces the second graph.
                    Sorry, I did not notice the follow up question with the label issue. It really is a different issue and should've been asked in a new thread. I highly recommend questions such as these be sent to Stata technical support as you'll always get a response there whereas Statalist posts (especially followup questions) can be easily missed due to the volume of posts. We will investigate the issue.
                    Last edited by Chinh Nguyen (StataCorp); 10 Aug 2022, 09:41. Reason: Removed extra signature.
                    -Chinh Nguyen

                    Comment


                    • #11
                      I couldn't reproduce your problems:

                      Code:
                      sysuse auto, clear
                      scatter price mpg, title("Good Title: Large", size(large)) name(g1)
                      graph export g1.png, width(800)
                      Click image for larger version

Name:	g1.png
Views:	1
Size:	43.7 KB
ID:	1677219


                      Code:
                      sysuse auto, clear
                      scatter price mpg, title("Good Title: Small", size(small)) name(g2)
                      graph export g2.png, width(800)
                      Click image for larger version

Name:	g2.png
Views:	1
Size:	42.0 KB
ID:	1677220


                      My initial observation of the graphs from the posts about labels and titles is that all text is rendered small including the axis labels.

                      Which font are you using for your graphs? Here's what I get when I enter graph set window in Stata:

                      Code:
                      . graph set window
                      
                         window           current
                         setting          default          choices
                         ------------------------------------------------------------------------
                         fontface         Helvetica         font name
                         fontfacesans     Helvetica         font name
                         fontfaceserif    Times             font name
                         fontfacemono     Courier           font name
                         fontfacesymbol   Symbol            font name
                         ------------------------------------------------------------------------
                         To change setting, type "graph set window setting choice"
                      -Chinh Nguyen

                      Comment


                      • #12
                        Hi Gabriel Cruz and Joe Emmens,


                        I confirm that Chinh is pointing to a bug. There's a problem with graph set window in Stata 17 for Mac that don't let the user to set up a different font typeface than the default. I had to overcome the issue getting back to the default setup.

                        Comment


                        • #13
                          I'm not aware of any problems with graph set window in Stata for Mac or any other version of Stata for Mac. I believe we have had a couple of users write in to technical support over the years with a similar issue but it was due to a bad font and the solution was to use a different font.

                          For each string in a graph, Stata loads the requested font at a size that Stata wants, asks the operating system what the size of the string it's going to render is so it knows where to put everything else, then tells the OS to render the string. If there are any problems with how the text appears on the screen our experience has shown that it's a problem with the font and the measurements we get back from the OS. I'm not aware of any issues that have come up with not just the Stata's default graph font, but any system font.

                          Code:
                          . graph set window fontface Georgia
                          
                          . graph set window
                          
                             window           current
                             setting          default          choices
                             ------------------------------------------------------------------------
                             fontface         Georgia           font name
                             fontfacesans     Helvetica         font name
                             fontfaceserif    Times             font name
                             fontfacemono     Courier           font name
                             fontfacesymbol   Symbol            font name
                             ------------------------------------------------------------------------
                             To change setting, type "graph set window setting choice"
                          
                          . sysuse auto, clear
                          (1978 automobile data)
                          
                          . scatter price mpg, title("Good Title: Large", size(large))
                          
                          . graph export g1.png, width(600) replace
                          Click image for larger version

Name:	g1.png
Views:	1
Size:	29.2 KB
ID:	1677958


                          Code:
                          . graph set window fontface ArialNarrow
                          
                          . graph set window
                          
                             window           current
                             setting          default          choices
                             ------------------------------------------------------------------------
                             fontface         ArialNarrow       font name
                             fontfacesans     Helvetica         font name
                             fontfaceserif    Times             font name
                             fontfacemono     Courier           font name
                             fontfacesymbol   Symbol            font name
                             ------------------------------------------------------------------------
                             To change setting, type "graph set window setting choice"
                          Click image for larger version

Name:	g2.png
Views:	1
Size:	28.4 KB
ID:	1677959


                          Code:
                          . graph set window fontface ComicSansMS
                          
                          . graph set window
                          
                             window           current
                             setting          default          choices
                             ------------------------------------------------------------------------
                             fontface         ComicSansMS       font name
                             fontfacesans     Helvetica         font name
                             fontfaceserif    Times             font name
                             fontfacemono     Courier           font name
                             fontfacesymbol   Symbol            font name
                             ------------------------------------------------------------------------
                             To change setting, type "graph set window setting choice"
                          
                          . scatter price mpg, title("Good Title: Small", size(small))
                          Click image for larger version

Name:	g3.png
Views:	1
Size:	29.7 KB
ID:	1677961
                          Attached Files
                          -Chinh Nguyen

                          Comment


                          • #14
                            Thanks, Chinh Nguyen (StataCorp) . I just read your reply. I apologize for my late reply.

                            Comment

                            Working...
                            X