【ROOT from CERN】——TCanvas绘制画布
ROOT使用TCanvas类来绘制画布,在平常的使用中,如果在绘制TGraph,TFunction,THistogram是不调用该类,则ROOT自动初始化一个默认的TCanvas。但是如果想要将多张图绘制到一张画布上,就需要自己初始化画布。本篇介绍TCanvas的基本用法。
一、继承关系-Inheritance
如图所示。TCanvas继承自TPad。
二、构造函数-Constructor
第一类构造函数,常用。
TCanvas::TCanvas ( const char * name,const char * title,Int_t ww,Int_t wh )
第二类构造函数,常用。
TCanvas::TCanvas ( const char * name,const char * title,Int_t wtopx,Int_t wtopy,Int_t ww,Int_t wh )
以上两类构造函数的参数列表如下:
name | canvas name |
title | canvas title |
wtopx,wtopy | are the pixel coordinates of the top left corner of the canvas (if wtopx < 0) the menubar is not shown) |
ww | is the canvas size in pixels along X |
wh | is the canvas size in pixels along Y |
Example:
TCanvas* c1 = new TCanvas("c1","test canvas",200,100);
第三类构造函数。
TCanvas::TCanvas ( const char * name,const char * title = "",Int_t form = 1 )
form是预定义的画布形式,其定义的值如下:
Create a new canvas with a predefined size form.
If form < 0 the menubar is not shown.
- form = 1 700x500 at 10,10 (set by TStyle::SetCanvasDefH,W,X,Y)
- form = 2 500x500 at 20,20
- form = 3 500x500 at 30,30
- form = 4 500x500 at 40,40
- form = 5 500x500 at 50,50
三、常用方法
1、分割画布和调用画板
(1)分割画布
void TPad::Divide ( Int_t nx = 1,Int_t ny = 1,Float_t xmargin = 0.01,Float_t ymargin = 0.01,Int_t color = 0 )
方法继承自TPad。通常只使用前两个参数。
Example:
c1->Divide(2,1);// create 2 pads (2 divisions along x, 1 along y).
(2)调用画板
TVirtualPad * TCanvas::cd ( Int_t subpadnumber = 0 )
Example:
c1->cd(2);//from top to bottom, from left to right, is 1,2,3....n
从上到下,从左到右的编号依次为1,2,3.……n。进入对应画板后可以调用Draw()方法进行画图,即可把多个图画在一张画布上。
(3)保存为图片格式
void TPad::SaveAs ( const char * filename = "",Option_t * option = "" ) const
Example:
c1->SaveAs("figure.png");
最常用的保存格式为pdf、png、jpg、jpeg、gif、root、cpp/cxx/C几类。
if filename is empty, the file produced is padname.ps
if filename starts with a dot, the padname is added in front
if filename ends with .ps, a Postscript file is produced
if filename ends with .eps, an Encapsulated Postscript file is produced
if filename ends with .pdf, a PDF file is produced NOTE: TMathText will be converted to TLatex; q.e.d., symbols only available in TMathText will not render properly.
if filename ends with .svg, a SVG file is produced
if filename ends with .tex, a TeX file is produced
if filename ends with .gif, a GIF file is produced
if filename ends with .gif+NN, an animated GIF file is produced See comments in TASImage::WriteImage for meaning of NN and other .gif sufix variants
if filename ends with .xpm, a XPM file is produced
if filename ends with .png, a PNG file is produced
if filename ends with .bmp, a BMP file is produced
if filename ends with .jpg or .jpeg a JPEG file is produced NOTE: JPEG's lossy compression will make all sharp edges fuzzy.
if filename ends with .tiff, a TIFF file is produced
if filename ends with .C, .cxx,.cpp or .cc, a C++ macro file is produced
if filename ends with .root, a Root file is produced
if filename ends with .xml, a XML file is produced
if filename ends with .json, a JSON file is produced
【资料】
1、ROOT官网——ROOT: analyzing petabytes of data, scientifically. - ROOT
2、ROOT文档——ROOT: TCanvas Class Reference
后续还会不断更新,如有错误请指正。
【ROOT from CERN】——TCanvas绘制画布相关推荐
- 【ROOT from CERN】——ROOT的安装
ROOT 是CERN(欧洲核子中心)开发的,基于C++的数据分析框架(语言),在大量数据的情况下表现十分良好.本篇文章将描述有关于ROOT在Linux(以Ubuntu为例)和Windows(以Win1 ...
- 【ROOT from CERN】——TH1绘制一维直方图
本篇文章具体介绍如何绘制出一张最简单的具备齐全要素的一维直方图,以及其各个要素最基本的绘制和修改方法. 一.创建直方图 1.直方图主体 (1)利用构造函数构造一维直方图 构建固定bin宽的直方图如下示 ...
- 【ROOT from CERN】——LaTeX与TLatex类
一.LaTeX简介 TeX 是由Donald Knuth创造的基于底层编程语言的电子排版系统.使用TeX可以对版面做精细的操作,生成精美的文档.TeX提供版面编辑的底层命令,但是使用时操作复杂,工作效 ...
- 【ROOT from CERN】——TSpectrum2类与二维寻峰
TSpectrum2类是二维谱类,其中的方法可以寻找在二维直方图(即散点图)内的峰个数.本篇文章会介绍部分该类的基本用法和原理. 一.基本简介 根据官网介绍,TSpectrum类以及TSpectrum ...
- 【ROOT from CERN】——传统的约定
在ROOT和C++编程中,有很多约定俗成的规定和命名规范.有些是为了程序便于在不同编译环境的计算机上移植,有些是为了增加程序的可阅读性.记住这些约定,有助于程序员理解程序,并理解ROOT的头文件.源文 ...
- 【ROOT from CERN】——如何读取Tree
了解.root的存储信息,从.root的Tree中读取数据进行分析,涉及到十分庞杂的代码,本文进行相关的总结. 一.用Cling查看Tree 1.打开.root文件查看基础内容 打开.root文件所在 ...
- java制作画布_java – 使用自定义方法绘制到画布?
我正在编写一个 Android 2-D游戏,我遇到了一些麻烦. 目前,在我的包中,我有一个绘制画布实例的线程.我正在从资源中绘制Drawable位图.我想做的是让线程处理背景图像的绘制.但是,自定义对 ...
- html 画星星的坐标,如何使用画布HTML5绘制星星?
在HTML画布上绘图将使用JavaScript完成.使用HTML DOM方法getElementById(),并getContext()在画布上绘制前.要在HTML中绘制星形,请使用canvas元素. ...
- 动画和图形:画布和可绘制对象
Android框架API提供了一组2D绘图API,允许您将自己的自定义图形呈现到画布上或修改现有视图以自定义其外观和感觉. 绘制2D图形时,通常可以通过以下两种方法之一进行: 1.将您的图形或动画绘制 ...
最新文章
- Debian 8 直接升级到 Debian 9
- FSLib.Extension库
- 深度学习必备:随机梯度下降(SGD)优化算法及可视化
- keras中lstm参数_如何使用Keras为自定义NER构建深度神经网络
- 鸟哥的Linux私房菜(基础篇)- 简易且较小安装Red Hat 7.2
- Codis 分布式缓存部署
- phpcms v9宽字节注入问题
- git 中遇到的错误及解决方法
- java if 局部变量_java – 为什么局部变量在if-else构造中启动而在if-else-if构造中不启动?...
- 机器学习十大经典算法——逻辑回归
- Redis 6.0 源码阅读笔记(1) -- Redis 服务端启动及命令执行
- 计算广告学涉及的学科与技术
- ruoyi 项目启动步骤
- 大话西游手游服务器维护要多久,大话西游手游7月22日维护及解读
- 【verbs】ibv_create_cq()
- 《东周列国志》第十六回 释槛囚鲍叔荐仲 战长勺曹刿败齐
- 逻辑思维训练和推理思维训练
- 软件测试团队口号及队名,团队队名口号(精选50句)
- Excel如何将文本中间的数值提取出来
- 维和步兵营~傻逼的戈瑞-冷酷的林皓南~装逼的海蓝