Announcement

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

  • Plot with text not exporting to PDF

    Dear all.

    What I am about to describe, happens happens in both Stata 15 and Stata 16, running on Windows 7 Professional.

    I have a quarterly database with three variables (VoHHIRev, VoHHITraf, and VoHHIUsers) I want to plot and export into a PDF file. These variables refer to HHI indicators for a couple of different markets identified with variable MarketType.

    In the plot, I use a text box to specify which plotted line refers to which market (mobile or fixed):
    Click image for larger version

Name:	ImageText.png
Views:	1
Size:	69.4 KB
ID:	1589305




    The command I use to get this plot is as follows:

    local a = yq(2014,1) // Obtain value for 2014q1 to use it in the graph command below
    graph twoway (line VoHHIUsers Quarter if(MarketType == 1), lcolor(navy)) || ///
    (line VoHHIRev Quarter if(MarketType == 1), lcolor(maroon) ) || ///
    (line VoHHITraf Quarter if(MarketType == 1), lcolor("85 117 47")) || ///
    (line VoHHIUsers Quarter if(MarketType == 2), lcolor(navy) lpattern(shortdash_dot)) || ///
    (line VoHHIRev Quarter if(MarketType == 2), lcolor(maroon) lpattern(shortdash_dot)) || ///
    (line VoHHITraf Quarter if(MarketType == 2), lcolor("85 117 47") lpattern(shortdash_dot)), ///
    xline(`a', lpattern("-") lcolor(green)) legend(order(1 "Users" 2 "Revenue" 3 "Traffic")) ///
    ttext(0.6 2017q2 "Mobile", placement(se) box just(left) margin(l+2 t+1 b+1) fcolor(white) width(12)) ttext(0.55 2017q2 "Fixed", placement(se) box just(left) margin(l+2 t+1 b+1) fcolor(white) width(12) lpattern(shortdash_dot))

    However, when I try to export this graph to PDF -graph export "$OutPath/HHIVoice.pdf", as(pdf) replace-, I get the next error message:

    unable to save PDF file
    r(691);

    It is worth noting that I have already checked path length and other recommendations given formerly in this same forum and other Internet resources. Even, I tried to export (unsuccessfuly) directly from the plot window File -> Save as ...

    After going back and forth with different command specifications to get the PDF exported successfuly, I realized that I can only export the plot if I remove the text boxes. I mean, the next plot command allows me to export to PDF (note there is no "ttext()" option written):

    graph twoway (line VoHHIUsers Quarter if(MarketType == 1), lcolor(navy)) || ///
    (line VoHHIRev Quarter if(MarketType == 1), lcolor(maroon) ) || ///
    (line VoHHITraf Quarter if(MarketType == 1), lcolor("85 117 47")) || ///
    (line VoHHIUsers Quarter if(MarketType == 2), lcolor(navy) lpattern(shortdash_dot)) || ///
    (line VoHHIRev Quarter if(MarketType == 2), lcolor(maroon) lpattern(shortdash_dot)) || ///
    (line VoHHITraf Quarter if(MarketType == 2), lcolor("85 117 47") lpattern(shortdash_dot)), ///
    xline(`a', lpattern("-") lcolor(green)) legend(order(1 "Users" 2 "Revenue" 3 "Traffic"))

    I still need the text box ("Mobile" and "Fixed" in the previous picture) in the PDF. Could you please let me know what to do (or what am I doing wrong) to get the plot I need in PDF format?.

    Renzo.
    Last edited by Renzo Clavijo; 12 Jan 2021, 09:30.

  • #2
    Attempting to replicate your problem using the example dataset xtline1 causes Stata to crash on my machine, but excluding the textboxes lets me export the graph as normal. Here is the code I used:

    Code:
    clear
    sysuse xtline1
    gen x = runiformint(1,2)
    global OutPath "C:\Users\myusername\Desktop"
    local a 15370
    graph twoway (line calories day if(x == 1), lcolor(navy)) || ///
    (line calories day if(x == 1), lcolor(maroon) ) || ///
    (line calories day if(x == 1), lcolor("85 117 47")) || ///
    (line calories day if(x == 2), lcolor(navy) lpattern(shortdash_dot)) || ///
    (line calories day if(x == 2), lcolor(maroon) lpattern(shortdash_dot)) || ///
    (line calories day if(x == 2), lcolor("85 117 47") lpattern(shortdash_dot)), ///
    xline(`a', lpattern("-") lcolor(green)) legend(order(1 "Users" 2 "Revenue" 3 "Traffic")) ///
    ttext(5000 15650 "Mobile", placement(se) box just(left) margin(l+2 t+1 b+1) fcolor(white) width(12)) ttext(4750 15650 "Fixed", placement(se) box just(left) margin(l+2 t+1 b+1) fcolor(white) width(12) lpattern(shortdash_dot))
    graph export "$OutPath/HHIVoice.pdf", as(pdf) replace
    The only explanation I can think of is that the bug listed as having been fully fixed in the 30 September 2019 update is recurring, for some reason:

    4. graph export, when exporting to a PDF file from a graph that
    contained twoway line connected lines, in rare cases incorrectly
    exited with error message "unable to save PDF file". This bug was
    partially fixed in the 23aug2019 update and is now fully fixed.
    Last edited by Ali Atia; 12 Jan 2021, 10:48.

    Comment


    • #3
      Hello Ali,

      Thank you for your reply.

      Is there anything I can do to escalate this problem to developers to let them know this issue is still there and have a fully working graph export release?.


      Comment


      • #4
        Stata Technical Services welcomes your questions at

        https://www.stata.com/support/tech-support/

        which is linked to from the Support tab at the top of the stata.com home page.

        Comment


        • #5
          Although not a resolution to the underlying problem, you could just screenshot your screen when the graph is displayed then use whatever photoeditor software you have to save it in whatever format you want.

          Comment


          • #6
            Thank you William for your reply. I will follow tech support request procedures to report the issue.

            Thank you Chris for your feedback. Indeed, that is what I am doing so far. However, I was trying to avoid it since my scripts generate PDF images that I further import into my paper without additional manipulation, keeping consistency and preserving image quality.

            Comment


            • #7
              Hi Renzo Clavijo,

              Thank you for reporting this bug to us. I can replicate it on my side. The bug is triggered when a line pattern other than solid is specified in the lpattern() option and when it is exported to a pdf file. We will fix it in one of our future updates.

              Comment


              • #8
                I took Ala Ataa's code and then saved the graph as emf (graph export test.emf
                That worked

                Comment

                Working...
                X