Print / saveas png draws axis title twice with offset

Hello rooters,
when I try to output my canvas directly to png, I encounter a problem with an axis title printed twice.
No that would not be to problem… but it is printed twice with offset for whatever reason.
For the fun of it… if I print it more than once the problem vanishes - what am I doing wrong?
It does not happen for other formats such as pdf.
I have included a minimal example.

#include <iostream>
#include <TF1.h>
#include <TCanvas.h>
#include <TAxis.h>




int png_double_x_axis_title(){
cout << "start" << endl; 

TF1 *fa1 = new TF1("fa1","sin(x)/x",0,10);

TCanvas *c1 = new TCanvas();

fa1->Draw();
fa1->GetXaxis()->SetTitle("X-axis");
fa1->GetYaxis()->SetTitle("Y-axis");



c1->Modified();
c1->Update();
// c1->SaveAs("testsave.png");
// c1->Print("test.png");
// c1->Print("test.pdf");
// c1->Print("test.png");
 c1->Print("test1.pdf");
 c1->Print("test2.pdf");
 c1->Print("test3.pdf");
 c1->Print("test1.png");
 c1->Print("test2.png");
 c1->Print("test3.png");


cout << "end" << endl;
return(0);
}

I was not able to reproduce the problem on a different computer… libs??

My machine:
OS: xubuntu 14.10
root version: 6.02/08 or 5.34/26 … happens for both… root was compiled locally
test1.pdf (14 KB)







png_double_x_axis_title.C (631 Bytes)

Yes … I cannot reproduce… will try to find some Ubuntu to test.

may this is of help:

ldd root yields:

	linux-vdso.so.1 =>  (0x00007fff739fe000)
	libXpm.so.4 => /usr/lib/x86_64-linux-gnu/libXpm.so.4 (0x00007fe6b5199000)
	libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007fe6b4f87000)
	libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007fe6b4c4d000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe6b493e000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe6b4727000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe6b4362000)
	libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fe6b4143000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe6b3f3f000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe6b3c38000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fe6b53d1000)
	libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fe6b3a34000)
	libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fe6b382e000)

configure yields:

Configuring for linuxx8664gcc
Checking for GNU Make version >= 3.80 ... ok
Checking for C compiler ... gcc
Checking for C++ compiler ... g++
Checking for linker (LD) ... g++
Checking for F77 compiler ... gfortran
Checking whether c++11 mode is supported ... yes
Checking for Python version >= 2.5 ... yes
Checking for libX11 ... /usr/lib/x86_64-linux-gnu
Checking for X11/Xlib.h ... /usr/include
Checking for X11/xpm.h ... /usr/include
Checking for X11/Xft/Xft.h ... /usr/include
Checking for X11/extensions/shape.h ... /usr/include
Checking for libXpm ... /usr/lib/x86_64-linux-gnu
Checking for libXft ... /usr/lib/x86_64-linux-gnu
Checking for libXext ... /usr/lib/x86_64-linux-gnu
Checking for freetype-config ... /usr/bin/freetype-config
Checking for libfreetype version >= 9.3.0 ... ok
Checking whether to build included libfreetype6 ... no
Checking for pcre-config ... /usr/bin/pcre-config
Checking for libpcre version >= 3.9 ... ok
Checking whether to build included libpcre ... no
Checking for zlib.h ... /usr/include
Checking for libz ... /usr/lib/x86_64-linux-gnu
Checking whether to build included zlib ... no
Checking for lzma.h ... no
Checking for liblzma ... no
Checking whether to build included lzma ... yes
Checking for GL/gl.h, or gl.h ... /usr/include
Checking for libGL, or libMesaGL ... /usr/lib/x86_64-linux-gnu
Checking for libGLU, or libMesaGLU ... /usr/lib/x86_64-linux-gnu
Checking for GL/glew.h ... /usr/include
Checking for libGLEW ... /usr/lib/x86_64-linux-gnu
Checking whether to build included GLEW ... no
Checking for pkg-config ... /usr/bin/pkg-config
Checking for libftgl ... ok
Checking for ftgl version > 2.1.2 ... ok
Checking whether to build included libftgl ... no
Checking for mysql_config ... /usr/bin/mysql_config
Checking for libmysqlclient version >= 3.23.* ... ok
Checking for mysql.h ... /usr/include/mysql
Checking for occi.h ... no
Checking for libclntsh, or oci ... no
Checking for libocci, or oraocci10 ... no
Checking for libpq-fe.h ... no
Checking for libpq ... no
Checking for sqlite3.h ... no
Checking for libsqlite3 ... no
Checking for sql.h ... no
Checking for libsqlod ... no
Checking for sqlext.h ... no
Checking for libiodbc, libodbc, or odbc32 ... no
Checking for rfio_api.h ... no
Checking for librfio, libdpm, libcastorrfio, libshift, shiftmd, or shift ... no
Checking for rfio_api.h ... no
Checking for stager_api.h ... no
Checking for libcastorrfio, libshift, shiftmd, or shift ... no
Checking for gfal_api.h ... no
Checking for libgfal ... no
Checking for gfal_srm_ifce_types.h ... no
Checking for ApMon.h ... no
Checking for libapmoncpp ... no
Checking for fftw3.h ... /usr/include
Checking for libfftw3, or libfftw3-3 ... /usr/lib/x86_64-linux-gnu
Checking for fitsio.h ... /usr/include
Checking for libcfitsio, or cfitsio ... /usr/lib/x86_64-linux-gnu
Checking for gvc.h ... /usr/include/graphviz
Checking for libgvc, or gvc ... /usr/lib
Checking for libgraph, graph, libcgraph, or cgraph ... /usr/lib
Checking for libcdt, or cdt ... /usr/lib
Checking for libpathplan, or pathplan ... /usr/lib
Checking for libexpat, or expat ... /usr/lib/x86_64-linux-gnu
Checking for libgvplugin_dot_layout, or gvplugin_dot_layout ... /usr/lib/graphviz
Checking for libPythia6 ... no
Checking for Pythia8/Pythia.h ... no
Checking for libpythia8 ... no
Checking for dcap.h ... no
Checking for libdcap ... no
Checking for davix.hpp ... no
Checking for libdavix ... no
Checking for chirp_reli.h ... no
Checking for libchirp_client ... no
Checking for hdfs.h ... no
Checking for jni.h ... no
Checking for libhdfs ... no
Checking for libjvm ... no
Checking for dns_sd.h ... /usr/include
Checking for libdns_sd ... /usr/lib/x86_64-linux-gnu
Checking for avahi-client/client.h ... /usr/include
Checking for avahi-common/strlst.h ... /usr/include
Checking for avahi-core/core.h ... no
Checking for libavahi-client ... /usr/lib/x86_64-linux-gnu
Checking for libavahi-common ... /usr/lib/x86_64-linux-gnu
Checking for libavahi-core ... no
Checking for libglite-api-wrapper ... no
Checking for gapiUI.h ... no
Checking for libgapiUI ... no
Checking for jpeglib.h ... no
Checking for png.h ... /usr/include
Checking for tiffio.h ... no
Checking for libjpeg ... no
Checking for libtiff ... no
Checking for libz ... /usr/lib/x86_64-linux-gnu
Checking for libpng ... /usr/lib/x86_64-linux-gnu
Checking whether to build included libAfterImage ... yes
Checking for ldap.h ... /usr/include
Checking for libldap ... /usr/lib/x86_64-linux-gnu
Checking for liblber ... /usr/lib/x86_64-linux-gnu
Checking for PyROOT prerequisites ... yes
Checking for Python.h ... /usr/include/python2.7
Checking for python2.7, libpython2.7, libpython, python, or Python ... /usr/lib/x86_64-linux-gnu
Checking for xml2-config ... /usr/bin/xml2-config
Checking for libxml2 version >= 2.4.x ... ok
Checking for XrdVersion.hh ... no
Checking for libssl ... /usr/lib/x86_64-linux-gnu
Checking for libcrypto ... /usr/lib/x86_64-linux-gnu
Checking for openssl/bio.h ... /usr/include
Checking for openssl/blowfish.h ... /usr/include
Checking for openssl/err.h ... /usr/include
Checking for openssl/pem.h ... /usr/include
Checking for openssl/rand.h ... /usr/include
Checking for openssl/rsa.h ... /usr/include
Checking for t_server.h ... no
Checking for libsrp ... no
Checking for libgmp ... no
Checking for libmisc ... no
Checking for pwauth.h ... no
Checking for krb5.h ... /usr/include
Checking for krb5.h redirect ... /usr/include/krb5/krb5.h
Checking for krb5_c_valid_cksumtype in krb5.h ... yes
Checking for valid_cksumtype in krb5.h ... no
Checking for libk5crypto ... /usr/lib/x86_64-linux-gnu
Checking whether we're using MIT Kerberos ... yes
Checking for krb5_c_valid_cksumtype in /usr/lib/x86_64-linux-gnu/libk5crypto.so ... ok
Checking for valid_cksumtype in /usr/lib/x86_64-linux-gnu/libk5crypto.so ... ok
Checking for libkrb5 ... /usr/lib/x86_64-linux-gnu
Checking for kinit ... /usr/bin/kinit
Checking for libcom_err ... /usr/lib/x86_64-linux-gnu
Checking for shadow passwords ... yes
Checking for gsl/gsl_version.h ... /usr/include
Checking for GSL version >= 1.10 ... ok
Checking for libgsl, gslML, or gsl ... /usr/lib
Checking for libgslcblas, gslcblasML, gslcblas, or cblas ... /usr/lib
Checking whether /usr/lib/libgsl.a is compiled with -fPIC ... yes
Checking whether /usr/lib/libgslcblas.a is compiled with -fPIC ... no
Checking for shared library versions using gsl-config ... yes
Checking whether to build libMathMore ... yes
Checking whether to build libGenVector ... yes
Checking whether to build libRooFit ... no
Checking whether to build libMinuit2 ... no
Checking whether to build libUnuran ... no
Checking whether to build libVc ... no
Checking whether to install VDT ... yes
Checking whether to build libGdml ... no
Checking whether to build libTable ... no
Checking whether to build libTMVA ... yes
Checking whether to build libRHTTP ... no
Checking whether to build libMemStat ... yes
Checking whether to build afdsmgrd ... no
Checking whether setresuid declared in /usr/include/unistd.h ... yes
Writing config/Makefile.config ... done
Writing config/Makefile.comp ... done
Writing include/RConfigure.h ... done
Writing include/RConfigOptions.h ... done
Writing bin/root-config ... done
Writing etc/system.rootrc ... done
Writing etc/system.rootauthrc ... done
Writing etc/system.rootdaemonrc ... done
Writing etc/root.mimes ... done
Writing etc/daemons/rootd.rc.d ... done
Writing etc/daemons/rootd.xinetd ... done
Writing etc/daemons/proofd.rc.d ... done
Writing etc/daemons/proofd.xinetd ... done
Writing main/src/proofserv.sh ... done
Writing main/src/roots.sh ... done
Writing bin/memprobe ... done
Writing build/misc/root-help.el ... done
Writing macros/html.C ... done
Writing bin/thisroot.sh ... done
Writing bin/thisroot.csh ... done
Writing bin/setxrd.sh ... done
Writing bin/setxrd.csh ... done
Writing config.status ... done

Enabled support for asimage, astiff, builtin_afterimage, builtin_lzma, builtin_llvm, explicitlink, fftw3, fitsio, gviz, genvector, krb5, ldap, mathmore, memstat, mysql, opengl, python, shadowpw, shared, ssl, tmva, vdt, x11, xft, xml.

To build ROOT type:

   make 

Probably I should clarify that everything looks alright on the screen.

Also my rootlogon.C seems to have an impact.
I tried to reduce it to the minimum required to generate the effect:

{

  gStyle->SetTitleXOffset(1.3);
  gStyle->SetTitleYOffset(1.3);


  gStyle->SetCanvasDefH(1200);
  gStyle->SetCanvasDefW(1600);
  
  int font = 43;

  int fontsize = 39;
  gStyle->SetTextFont(font);
  gStyle->SetTextSizePixels(fontsize);
  gStyle->SetLabelFont(font, "XYZ");
  gStyle->SetLabelSize(fontsize,"xyz");
  gStyle->SetTitleFont(font, "XYZ");
  gStyle->SetTitleSize(fontsize,"xyz");
  gStyle->SetStatFont(font);
  gStyle->SetStatFontSize(fontsize);
  gStyle->SetLegendFont(font);
  gStyle->SetTitleFont(font);

}

Still looking for an ubuntu machine…

I just tried on Ubuntu with 5.34
It works … I do not see the 2 titles on png files.

I am able to reproduce this problem on my Ubuntu 14.04.
It is related to two lines in the “rootlogon.C”:
gStyle->SetCanvasDefH(RequestedH);
gStyle->SetCanvasDefW(RequestedW);
As soon as “RequestedH” and/or “RequestedW” exceed physical dimensions of my screen, I also get “spurious” contents in the “bottom” and/or “right” side in the “test1.png” file (but not in another saved pictures and not on the screen).
I can clearly see that, when the “png_double_x_axis_title” macro starts, ROOT opens a canvas with “RequestedH” x “RequestedW” pixels and the “fa1” function is drawn (so that I do not see its “bottom” and/or “right” side on the screen) but then it is immediately “automatically resized” so that it fully fits my screen dimensions.
Thus, for some reason, the “test1.png” file uses the original “RequestedH” x “RequestedW” pixels size, while the two remaining saved “.png” pictures use the actually available physical size of my screen (in pixels).

I can reproduce the effect on Mac with the X11 version using:

void png_double_x_axis_title(){

   gStyle->SetCanvasDefH(2000);
   gStyle->SetCanvasDefW(1000);

   TF1 *fa1 = new TF1("fa1","sin(x)/x",0,10);

   TCanvas *c1 = new TCanvas();

   fa1->Draw();
   fa1->GetXaxis()->SetTitle("X-axis");
   fa1->GetYaxis()->SetTitle("Y-axis");

   c1->Modified();
   c1->Update();

   c1->Print("test1.png");
}

It gives me the attached plot.


This problem is now fixed in the ROOT master.

How about “v5-34-00-patches”? I could then test it.

Now also fixed in “v5-34-00-patches”. Thanks.

This problem seems to be gone now in “v5-34-00-patches”.

Unfortunately, the other problem related to TCanvas::SetWindowSize is still there.

Yes I know it is . I tested it also .

This is not connected. Thanks for the reminder.