fabstr
August 20, 2021, 10:10am
1
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.22/00
Platform: Ubuntu 20.04.1 LTS (WSL2)
Compiler: GNU or GCC
Hello,
I have created a contour plot of the magnetic flux density of an octupole magnet. But I think there is a better way to do it. My code is little bit messy and I want my plot to show the contour line of the magnetic field by a radial distance less than 50 mm. My code is shown below and I want to improve the code so that my contour plot can become much simpler to interpret. I have two x and y positions and the magnetic field flux (B_mag = sqrt(B_x^2 + B_y^2 + B_z^")) that I want to plot.
#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TH1F.h"
#include <iostream>
using namespace std;
void Contour_Plot(){
const Int_t NRGBs = 5;
const Int_t NCont = 99;
Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
gStyle->SetNumberContours(NCont);
TGraph2D *g=new TGraph2D("Test_data.txt","%lg %lg %lg");
g->SetNpx(200);
g->SetNpy(200);
g->SetTitle("Contour plot of the magnetic flux density (T) in the x-y plane");
g->GetHistogram()->GetXaxis()->SetTitle("x (m)");
g->GetHistogram()->GetYaxis()->SetTitle("y (m)");
TCanvas *c = new TCanvas("c", "c");
g->SetLineColor(kWhite);
g->SetLineWidth(1);
g->SetLineStyle(1);
g->Draw("COLZ CONT3");
g->GetHistogram()->GetYaxis()->SetRangeUser(-50.0, 50.0);
g->GetHistogram()->GetXaxis()->SetRangeUser(-50.0, 50.0);
c->SetRealAspectRatio();
c->Modified(); c->Update();
gPad->Update();
}
couet
August 20, 2021, 10:47am
2
Can you also post Test_data.txt
?
fabstr
August 20, 2021, 11:40am
3
Sure,
the first and second column is the x and y positions. The third, fourth and fifth columns are the magnetic field in the x,y and z directions. I reduced all the data due to the limited size that can be allowed here.
-0.0540000000000000 -0.0540000000000000 1.8540000000000001 2.1671304156105324 2.1671337870455591 0.6314719501482401
-0.0540000000000000 -0.0440000000000000 1.8540000000000001 1.1681125191097685 2.0362095130334983 0.6498627194105220
-0.0540000000000000 -0.0340000000000000 1.8540000000000001 0.3727889845003144 1.7396170659902923 0.6635834512715635
-0.0540000000000000 -0.0240000000000000 1.8540000000000001 -0.2186941242957418 1.3151506489580644 0.6732812742968249
-0.0540000000000000 -0.0140000000000000 1.8540000000000001 -0.6062520496906045 0.8004806203684057 0.6794100800985956
-0.0540000000000000 -0.0040000000000000 1.8540000000000001 -0.7898391311537749 0.2332117708771450 0.6822525940713834
-0.0540000000000000 0.0060000000000000 1.8540000000000001 -0.7694363593058535 -0.3490819919563398 0.6819384596644275
-0.0540000000000000 0.0160000000000000 1.8540000000000001 -0.5450460651273676 -0.9088346736663232 0.6784534261235351
-0.0540000000000000 0.0260000000000000 1.8540000000000001 -0.1166924916707660 -1.4084682914406748 0.6716383128700812
-0.0540000000000000 0.0360000000000000 1.8540000000000001 0.5155716134640357 -1.8103683236028796 0.6611778699544093
-0.0540000000000000 0.0460000000000000 1.8540000000000001 1.3516508508299221 -2.0768453985302626 0.6465813169521549
-0.0440000000000000 -0.0540000000000000 1.8540000000000001 2.0362058073666911 1.1681165033175547 0.6498625094143727
-0.0440000000000000 -0.0440000000000000 1.8540000000000001 1.2219818863908047 1.2219851284678509 0.6669751542490023
-0.0440000000000000 -0.0340000000000000 1.8540000000000001 0.5738053098403560 1.1103392006157817 0.6797280485536088
-0.0440000000000000 -0.0240000000000000 1.8540000000000001 0.0917715675998831 0.8709090714844199 0.6887381871645147
-0.0440000000000000 -0.0140000000000000 1.8540000000000001 -0.2240651753908947 0.5413254496813544 0.6944319605373664
-0.0440000000000000 -0.0040000000000000 1.8540000000000001 -0.3736762924866999 0.1591676322690864 0.6970727866780950
-0.0440000000000000 0.0060000000000000 1.8540000000000001 -0.3570500570406727 -0.2380088161394996 0.6967809638575740
-0.0440000000000000 0.0160000000000000 1.8540000000000001 -0.1741880012365545 -0.6126543466427038 0.6935432828836511
-0.0440000000000000 0.0260000000000000 1.8540000000000001 0.1748946932339943 -0.9272102920864831 0.6872119559492301
-0.0440000000000000 0.0360000000000000 1.8540000000000001 0.6901646676269729 -1.1440898156496757 0.6774928915537916
-0.0440000000000000 0.0460000000000000 1.8540000000000001 1.3715605305325935 -1.2256471152510322 0.6639239711389078
-0.0340000000000000 -0.0540000000000000 1.8540000000000001 1.7396145024927199 0.3727941883139620 0.6635831607622943
-0.0340000000000000 -0.0440000000000000 1.8540000000000001 1.1103373480000831 0.5738087611451698 0.6797279535279726
-0.0340000000000000 -0.0340000000000000 1.8540000000000001 0.6094075787451738 0.6094093273121008 0.6917552215408966
-0.0340000000000000 -0.0240000000000000 1.8540000000000001 0.2368862485578866 0.5172831443794866 0.7002528543025989
-0.0340000000000000 -0.0140000000000000 1.8540000000000001 -0.0071926814498972 0.3350349113006517 0.7056235394768459
-0.0340000000000000 -0.0040000000000000 1.8540000000000001 -0.1228115852826090 0.1002276643458267 0.7081148415018015
-0.0340000000000000 0.0060000000000000 1.8540000000000001 -0.1099633730018227 -0.1495944359356294 0.7078395484356170
-0.0340000000000000 0.0160000000000000 1.8540000000000001 0.0313509346527963 -0.3768919637726617 0.7047852833651426
-0.0340000000000000 0.0260000000000000 1.8540000000000001 0.3011219465877408 -0.5441183140334290 0.6988134398379919
-0.0340000000000000 0.0360000000000000 1.8540000000000001 0.6993288822997065 -0.6137044081382008 0.6896474204331393
-0.0340000000000000 0.0460000000000000 1.8540000000000001 1.2259329400894798 -0.5480331844150635 0.6768501890924912
-0.0240000000000000 -0.0540000000000000 1.8540000000000001 1.3151505044462974 -0.2186879230703753 0.6732810160975246
-0.0240000000000000 -0.0440000000000000 1.8540000000000001 0.8709091881313991 0.0917752038915914 0.6887380973089781
-0.0240000000000000 -0.0340000000000000 1.8540000000000001 0.5172831133053795 0.2368879348195941 0.7002528468453445
-0.0240000000000000 -0.0240000000000000 1.8540000000000001 0.2543094526714856 0.2543096072258075 0.7083897743218045
-0.0240000000000000 -0.0140000000000000 1.8540000000000001 0.0820085547850377 0.1816284179220737 0.7135335295346755
-0.0240000000000000 -0.0040000000000000 1.8540000000000001 0.0003908053879096 0.0563973166861254 0.7159199151705099
-0.0240000000000000 0.0060000000000000 1.8540000000000001 0.0094602917113839 -0.0838464541504925 0.7156562124510013
-0.0240000000000000 0.0160000000000000 1.8540000000000001 0.1092163274572341 -0.2015695546571197 0.7127306526031162
-0.0240000000000000 0.0260000000000000 1.8540000000000001 0.2996532897462217 -0.2592327260094180 0.7070113713649681
-0.0240000000000000 0.0360000000000000 1.8540000000000001 0.5807587195488527 -0.2192779567894390 0.6982347981479048
-0.0240000000000000 0.0460000000000000 1.8540000000000001 0.9525091250173923 -0.0441064975899959 0.6859831317672922
-0.0140000000000000 -0.0540000000000000 1.8540000000000001 0.8004838401957557 -0.6062457702197457 0.6794099503672825
-0.0140000000000000 -0.0440000000000000 1.8540000000000001 0.5413279159842429 -0.2240619433564027 0.6944319612677594
-0.0140000000000000 -0.0340000000000000 1.8540000000000001 0.3350365451213609 -0.0071914487842500 0.7056235992359783
-0.0140000000000000 -0.0240000000000000 1.8540000000000001 0.1816294414547467 0.0820085075131571 0.7135335860088708
-0.0140000000000000 -0.0140000000000000 1.8540000000000001 0.0811172791771950 0.0811164746417177 0.7185347292467611
-0.0140000000000000 -0.0040000000000000 1.8540000000000001 0.0335054262365505 0.0276795933422610 0.7208552162171129
-0.0140000000000000 0.0060000000000000 1.8540000000000001 0.0387959273261635 -0.0407688176123299 0.7205987857009588
-0.0140000000000000 0.0160000000000000 1.8540000000000001 0.0969883267435759 -0.0866988476856356 0.7177540590931092
-0.0140000000000000 0.0260000000000000 1.8540000000000001 0.2080795804813572 -0.0725754159574383 0.7121935123107086
-0.0140000000000000 0.0360000000000000 1.8540000000000001 0.3720630308271970 0.0391530949405849 0.7036620259903548
-0.0140000000000000 0.0460000000000000 1.8540000000000001 0.5889261333110173 0.2860746988914195 0.6917544784677429
-0.0040000000000000 -0.0540000000000000 1.8540000000000001 0.2332188370548457 -0.7898342575205763 0.6822526722958823
-0.0040000000000000 -0.0440000000000000 1.8540000000000001 0.1591724973341964 -0.3736744869016115 0.6970729486252127
-0.0040000000000000 -0.0340000000000000 1.8540000000000001 0.1002307112315934 -0.1228114984830924 0.7081150302510887
-0.0040000000000000 -0.0240000000000000 1.8540000000000001 0.0563990975088087 0.0003900619730265 0.7159200810356432
-0.0040000000000000 -0.0140000000000000 1.8540000000000001 0.0276806973459717 0.0335044123658924 0.7208553167510232
-0.0040000000000000 -0.0040000000000000 1.8540000000000001 0.0140770056296469 0.0140760841281089 0.7231453532339599
-0.0040000000000000 0.0060000000000000 1.8540000000000001 0.0155885173943218 -0.0203633699531863 0.7228922731450930
-0.0040000000000000 0.0160000000000000 1.8540000000000001 0.0322149542767763 -0.0322855845890874 0.7200848795744347
-0.0040000000000000 0.0260000000000000 1.8540000000000001 0.0639552403318884 0.0158426414934354 0.7145976772932546
-0.0040000000000000 0.0360000000000000 1.8540000000000001 0.1108072197863019 0.1615700543560487 0.7061795133799547
-0.0040000000000000 0.0460000000000000 1.8540000000000001 0.1727670304245438 0.4424798475753799 0.6944312646425048
0.0060000000000000 -0.0540000000000000 1.8540000000000001 -0.3490711926379524 -0.7694348084552284 0.6819388086572369
0.0060000000000000 -0.0440000000000000 1.8540000000000001 -0.2380019663715895 -0.3570510009900907 0.6967813428620512
0.0060000000000000 -0.0340000000000000 1.8540000000000001 -0.1495905589251378 -0.1099652932625754 0.7078399150438286
0.0060000000000000 -0.0240000000000000 1.8540000000000001 -0.0838445358901955 0.0094583208814770 0.7156565296039779
0.0060000000000000 -0.0140000000000000 1.8540000000000001 -0.0407679389359996 0.0387943708015736 0.7205990216938208
0.0060000000000000 -0.0040000000000000 1.8540000000000001 -0.0203628385907524 0.0155875110606288 0.7228924016321805
0.0060000000000000 0.0060000000000000 1.8540000000000001 -0.0226301572204979 -0.0226306745877865 0.7226389342865294
0.0060000000000000 0.0160000000000000 1.8540000000000001 -0.0475700101339087 -0.0383318140033911 0.7198274016047870
0.0060000000000000 0.0260000000000000 1.8540000000000001 -0.0951816691525489 0.0060173374719314 0.7143320827976268
0.0060000000000000 0.0360000000000000 1.8540000000000001 -0.1654631374760280 0.1479656776732790 0.7059013845098278
0.0060000000000000 0.0460000000000000 1.8540000000000001 -0.2584102059976720 0.4250967651663807 0.6941355166160393
0.0160000000000000 -0.0540000000000000 1.8540000000000001 -0.9088209815166294 -0.5450500548108297 0.6784540920167008
0.0160000000000000 -0.0440000000000000 1.8540000000000001 -0.6126465212759694 -0.1741931866433346 0.6935439199908322
0.0160000000000000 -0.0340000000000000 1.8540000000000001 -0.3768883025671698 0.0313461092687295 0.7047858637909233
0.0160000000000000 -0.0240000000000000 1.8540000000000001 -0.2015684497458362 0.1092126930402225 0.7127311519158778
0.0160000000000000 -0.0140000000000000 1.8540000000000001 -0.0866989180113682 0.0969861213150902 0.7177544563301638
0.0160000000000000 -0.0040000000000000 1.8540000000000001 -0.0322858079596487 0.0322139548142349 0.7200851572471492
0.0160000000000000 0.0060000000000000 1.8540000000000001 -0.0383316591467598 -0.0475703558183221 0.7198275457037128
0.0160000000000000 0.0160000000000000 1.8540000000000001 -0.1048364022473572 -0.1048368436278747 0.7169701790111459
0.0160000000000000 0.0260000000000000 1.8540000000000001 -0.2317972573193159 -0.1020502569780614 0.7113848496969191
0.0160000000000000 0.0360000000000000 1.8540000000000001 -0.4192075473519968 -0.0016584690604614 0.7028151074653066
0.0160000000000000 0.0460000000000000 1.8540000000000001 -0.6670540695574725 0.2339277082788002 0.6908538259772790
0.0260000000000000 -0.0540000000000000 1.8540000000000001 -1.4084534057475855 -0.1167044083912686 0.6716393251100675
0.0260000000000000 -0.0440000000000000 1.8540000000000001 -0.9272032271482713 0.1748837376644043 0.6872128774040427
0.0260000000000000 -0.0340000000000000 1.8540000000000001 -0.5441165094308716 0.3011134132035695 0.6988142571247293
0.0260000000000000 -0.0240000000000000 1.8540000000000001 -0.2592338480468235 0.2996477827251262 0.7070120726793657
0.0260000000000000 -0.0140000000000000 1.8540000000000001 -0.0725774897178031 0.2080769790229607 0.7121940874322680
0.0260000000000000 -0.0040000000000000 1.8540000000000001 0.0158411000932625 0.0639548305366006 0.7145981175903701
0.0260000000000000 0.0060000000000000 1.8540000000000001 0.0060171896260889 -0.0951810624047146 0.7143323812327138
0.0260000000000000 0.0160000000000000 1.8540000000000001 -0.1020489050196095 -0.2317971384899239 0.7113850008315419
0.0260000000000000 0.0260000000000000 1.8540000000000001 -0.3083516395930080 -0.3083537106063819 0.7056229537699362
0.0260000000000000 0.0360000000000000 1.8540000000000001 -0.6128781419849709 -0.2872917273106375 0.6967804266815194
0.0260000000000000 0.0460000000000000 1.8540000000000001 -1.0156035777392758 -0.1310102042075007 0.6844362808124194
0.0360000000000000 -0.0540000000000000 1.8540000000000001 -1.8103549345116605 0.5155493465072630 0.6611792412969745
0.0360000000000000 -0.0440000000000000 1.8540000000000001 -1.1440861059695226 0.6901465084616938 0.6774941087956173
0.0360000000000000 -0.0340000000000000 1.8540000000000001 -0.6137068276835413 0.6993160652800576 0.6896484847038409
0.0360000000000000 -0.0240000000000000 1.8540000000000001 -0.2192833140670756 0.5807514901169575 0.6982357102705694
0.0360000000000000 -0.0140000000000000 1.8540000000000001 0.0391475006763130 0.3720607773919850 0.7036627864866746
0.0360000000000000 -0.0040000000000000 1.8540000000000001 0.1615663010481042 0.1108086056023269 0.7061801224753511
0.0360000000000000 0.0060000000000000 1.8540000000000001 0.1479650884067642 -0.1654600424297698 0.7059018421385806
0.0360000000000000 0.0160000000000000 1.8540000000000001 -0.0016554581134653 -0.4192051344932485 0.7028154132756816
0.0360000000000000 0.0260000000000000 1.8540000000000001 -0.2872856989462327 -0.6128791322493964 0.6967805800408962
0.0360000000000000 0.0360000000000000 1.8540000000000001 -0.7089037496163725 -0.7089110615787392 0.6875175856887622
0.0360000000000000 0.0460000000000000 1.8540000000000001 -1.2664682767586253 -0.6696801005442448 0.6745847974104981
0.0460000000000000 -0.0540000000000000 1.8540000000000001 -2.0768373189223484 1.3516159057965345 0.6465830434572202
0.0460000000000000 -0.0440000000000000 1.8540000000000001 -1.2256503463394848 1.3715339616664797 0.6639254807964547
0.0460000000000000 -0.0340000000000000 1.8540000000000001 -0.5480430542791122 1.2259156230955572 0.6768514975446511
0.0460000000000000 -0.0240000000000000 1.8540000000000001 -0.0441188249700912 0.9525008146334069 0.6859842524645069
0.0460000000000000 -0.0140000000000000 1.8540000000000001 0.2860634725384427 0.5889255951863570 0.6917554226738947
0.0460000000000000 -0.0040000000000000 1.8540000000000001 0.4424725260211417 0.1727721729990598 0.6944320414400411
0.0460000000000000 0.0060000000000000 1.8540000000000001 0.4250952653557947 -0.2584021996148475 0.6941361329111045
0.0460000000000000 0.0160000000000000 1.8540000000000001 0.2339329282749119 -0.6670466097091081 0.6908542865048398
0.0460000000000000 0.0260000000000000 1.8540000000000001 -0.1309985172786769 -1.0156005363412233 0.6844365881413943
0.0460000000000000 0.0360000000000000 1.8540000000000001 -0.6696634825488845 -1.2664738554210018 0.6745849519488839
0.0460000000000000 0.0460000000000000 1.8540000000000001 -1.3819961370878322 -1.3820147352361989 0.6608316869316060
couet
August 20, 2021, 1:43pm
4
Your macro gives me this plot, is it what you get also ?
fabstr
August 20, 2021, 1:48pm
5
Sorry,
I posted the wrong data. This should be right
-0.0540000000000000 -0.0540000000000000 3.1291660091856306
-0.0540000000000000 -0.0440000000000000 2.4357663254813104
-0.0540000000000000 -0.0340000000000000 1.8988370546339484
-0.0540000000000000 -0.0240000000000000 1.4935715663385722
-0.0540000000000000 -0.0140000000000000 1.2123979661311821
-0.0540000000000000 -0.0040000000000000 1.0694401270265372
-0.0540000000000000 0.0060000000000000 1.0857857113167149
-0.0540000000000000 0.0160000000000000 1.2583142407951051
-0.0540000000000000 0.0260000000000000 1.56476774280438
-0.0540000000000000 0.0360000000000000 1.9950949179004138
-0.0540000000000000 0.0460000000000000 2.5609205827938437
-0.0440000000000000 -0.0540000000000000 2.4357650823548265
-0.0440000000000000 -0.0440000000000000 1.8523885232988515
-0.0440000000000000 -0.0340000000000000 1.4227212987846838
-0.0440000000000000 -0.0240000000000000 1.114120694481642
-0.0440000000000000 -0.0140000000000000 0.9085561034473565
-0.0440000000000000 -0.0040000000000000 0.8067705848975394
-0.0440000000000000 0.0060000000000000 0.8183132965968253
-0.0440000000000000 0.0160000000000000 0.9416417012154975
-0.0440000000000000 0.0260000000000000 1.167290603008557
-0.0440000000000000 0.0360000000000000 1.49808724472905
-0.0440000000000000 0.0460000000000000 1.955552141849172
-0.0340000000000000 -0.0540000000000000 1.8988356262117414
-0.0340000000000000 -0.0440000000000000 1.4227211995110418
-0.0340000000000000 -0.0340000000000000 1.1051165602668966
-0.0340000000000000 -0.0240000000000000 0.9022477521024336
-0.0340000000000000 -0.0140000000000000 0.7811560061348227
-0.0340000000000000 -0.0040000000000000 0.725641026220933
-0.0340000000000000 0.0060000000000000 0.7317836189710558
-0.0340000000000000 0.0160000000000000 0.7998454407622148
-0.0340000000000000 0.0260000000000000 0.9354567815145595
-0.0340000000000000 0.0360000000000000 1.1581483284523184
-0.0340000000000000 0.0460000000000000 1.5037879249718333
-0.0240000000000000 -0.0540000000000000 1.493570414704141
-0.0240000000000000 -0.0440000000000000 1.114121029648856
-0.0240000000000000 -0.0340000000000000 0.9022481712306253
-0.0240000000000000 -0.0240000000000000 0.7944575170574648
-0.0240000000000000 -0.0140000000000000 0.7408403222186396
-0.0240000000000000 -0.0040000000000000 0.7181379637618363
-0.0240000000000000 0.0060000000000000 0.7206133078236815
-0.0240000000000000 0.0160000000000000 0.7486945136088412
-0.0240000000000000 0.0260000000000000 0.8104682470827466
-0.0240000000000000 0.0360000000000000 0.9342886845137425
-0.0240000000000000 0.0460000000000000 1.1746454245602445
-0.0140000000000000 -0.0540000000000000 1.2123968793187938
-0.0140000000000000 -0.0440000000000000 0.9085567763847663
-0.0140000000000000 -0.0340000000000000 0.781156749507556
-0.0140000000000000 -0.0240000000000000 0.7408406223138533
-0.0140000000000000 -0.0140000000000000 0.7276345597709936
-0.0140000000000000 -0.0040000000000000 0.7221641200047996
-0.0140000000000000 0.0060000000000000 0.7227930757971472
-0.0140000000000000 0.0160000000000000 0.7294479522619624
-0.0140000000000000 0.0260000000000000 0.7455091560753337
-0.0140000000000000 0.0360000000000000 0.7969341946312738
-0.0140000000000000 0.0460000000000000 0.9524688878502339
-0.0040000000000000 -0.0540000000000000 1.0694381184365775
-0.0040000000000000 -0.0440000000000000 0.8067708483663969
-0.0040000000000000 -0.0340000000000000 0.7256416165719507
-0.0040000000000000 -0.0240000000000000 0.7181382685654851
-0.0040000000000000 -0.0140000000000000 0.7221642156336473
-0.0040000000000000 -0.0040000000000000 0.7234193114202491
-0.0040000000000000 0.0060000000000000 0.7233470171938798
-0.0040000000000000 0.0160000000000000 0.7215278206992729
-0.0040000000000000 0.0260000000000000 0.717628805475584
-0.0040000000000000 0.0360000000000000 0.7328523913715066
-0.0040000000000000 0.0460000000000000 0.8413510822629487
0.0060000000000000 -0.0540000000000000 1.0857813595494574
0.0060000000000000 -0.0440000000000000 0.8183120389346672
0.0060000000000000 -0.0340000000000000 0.7317834695940554
0.0060000000000000 -0.0240000000000000 0.7206133737291783
0.0060000000000000 -0.0140000000000000 0.7227931779679931
0.0060000000000000 -0.0040000000000000 0.7233471089553617
0.0060000000000000 0.0060000000000000 0.723347289201317
0.0060000000000000 0.0160000000000000 0.7224152005114718
0.0060000000000000 0.0260000000000000 0.720670578702164
0.0060000000000000 0.0360000000000000 0.7399788215115453
0.0060000000000000 0.0460000000000000 0.8539948534660476
0.0160000000000000 -0.0540000000000000 1.2583064386978016
0.0160000000000000 -0.0440000000000000 0.941638038346347
0.0160000000000000 -0.0340000000000000 0.799844037908496
0.0160000000000000 -0.0240000000000000 0.7486941613004415
0.0160000000000000 -0.0140000000000000 0.7294480582563068
0.0160000000000000 -0.0040000000000000 0.7215280631881427
0.0160000000000000 0.0060000000000000 0.7224153586403432
0.0160000000000000 0.0160000000000000 0.7321391074169578
0.0160000000000000 0.0260000000000000 0.7551242466166437
0.0160000000000000 0.0360000000000000 0.8183439335377097
0.0160000000000000 0.0460000000000000 0.9884140393990776
0.0260000000000000 -0.0540000000000000 1.5647556672318639
0.0260000000000000 -0.0440000000000000 1.1672838922059983
0.0260000000000000 -0.0340000000000000 0.9354535955391516
0.0260000000000000 -0.0240000000000000 0.8104671816795672
0.0260000000000000 -0.0140000000000000 0.7455091812892316
0.0260000000000000 -0.0040000000000000 0.717629173365207
0.0260000000000000 0.0060000000000000 0.7206707931428092
0.0260000000000000 0.0160000000000000 0.7551241698130918
0.0260000000000000 0.0260000000000000 0.8294977380146555
0.0260000000000000 0.0360000000000000 0.9714211838901601
0.0260000000000000 0.0460000000000000 1.2316928688661168
0.0360000000000000 -0.0540000000000000 1.9950774688509785
0.0360000000000000 -0.0440000000000000 1.4980765963284857
0.0360000000000000 -0.0340000000000000 1.1581425050305691
0.0360000000000000 -0.0240000000000000 0.9342861297259811
0.0360000000000000 -0.0140000000000000 0.7969335392420885
0.0360000000000000 -0.0040000000000000 0.7328523603627136
0.0360000000000000 0.0060000000000000 0.7399784481744887
0.0360000000000000 0.0160000000000000 0.8183429540632309
0.0360000000000000 0.0260000000000000 0.971420135825857
0.0360000000000000 0.0360000000000000 1.2156396876049054
0.0360000000000000 0.0460000000000000 1.5835018099131666
0.0460000000000000 -0.0540000000000000 2.5608960225196875
0.0460000000000000 -0.0440000000000000 1.9555360450621848
0.0460000000000000 -0.0340000000000000 1.503777993595392
0.0460000000000000 -0.0240000000000000 1.174639803183654
0.0460000000000000 -0.0140000000000000 0.9524658690919564
0.0460000000000000 -0.0040000000000000 0.8413489289378872
0.0460000000000000 0.0060000000000000 0.8539921852139443
0.0460000000000000 0.0160000000000000 0.9884105622856332
0.0460000000000000 0.0260000000000000 1.2316892887950373
0.0460000000000000 0.0360000000000000 1.5834993096684047
0.0460000000000000 0.0460000000000000 2.0631472486927693
couet
August 20, 2021, 1:57pm
6
I simplified your macro:
void Contour_Plot(){
const Int_t NCont = 50;
gStyle->SetNumberContours(NCont);
auto g = new TGraph2D("Test_data.txt","%lg %lg %lg");
g->SetNpx(200);
g->SetNpy(200);
g->SetTitle("Contour plot of the magnetic flux density (T) in the x-y plane");
g->GetHistogram()->GetXaxis()->SetTitle("x (m)");
g->GetHistogram()->GetYaxis()->SetTitle("y (m)");
g->SetLineWidth(1);
g->SetLineStyle(1);
g->Draw("colz cont3 ");
}
it gives me this plot:
What’s wrong with it ?
fabstr
August 20, 2021, 2:03pm
7
Yes, thanks for the help. Is it possible to remove some of the contour lines? I want to see the contour lines in the case when r <= 0.05.
couet
August 20, 2021, 2:04pm
8
Which value of contour level do you want to see ?
{
const Int_t NRGBs = 5;
const Int_t NCont = 99;
Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
gStyle->SetNumberContours(NCont);
//
TGraph2D *g = new TGraph2D("Test_data.txt", "%lg %lg %lg");
g->SetNpx(200);
g->SetNpy(200);
g->SetTitle("Contour plot of the magnetic flux density (T) in the x-y plane");
g->GetHistogram()->SetXTitle(" x [m]");
g->GetHistogram()->GetXaxis()->CenterTitle(kTRUE);
g->GetHistogram()->GetXaxis()->SetTitleOffset(1.1);
g->GetHistogram()->GetXaxis()->SetTitleSize(0.032);
g->GetHistogram()->GetXaxis()->SetLabelSize(0.032);
g->GetHistogram()->SetYTitle(" y [m]");
g->GetHistogram()->GetYaxis()->CenterTitle(kTRUE);
g->GetHistogram()->GetYaxis()->SetTitleOffset(1.3);
g->GetHistogram()->GetYaxis()->SetTitleSize(0.032);
g->GetHistogram()->GetYaxis()->SetLabelSize(0.032);
g->GetHistogram()->GetZaxis()->SetLabelSize(0.032);
g->Draw("colz");
gPad->GetCanvas()->SetRealAspectRatio();
gPad->Modified(); gPad->Update();
//
TH2 *h = (TH2*)g->GetHistogram()->Clone();
h->SetLineColor(kWhite);
h->SetLineWidth(1);
h->SetLineStyle(1);
Double_t dl = 0.05;
Double_t lmin = dl * Int_t(h->GetMinimum() / dl);
#if 1 /* 0 or 1 */
Int_t nlevels = 11;
#else /* 0 or 1 */
Double_t lmax = 1.2;
if (lmax <= lmin) lmax = lmin + 2 * dl;// just a precaution
Int_t nlevels = 1 + Int_t((lmax - lmin) / dl + 0.5);
#endif /* 0 or 1 */
Double_t *levels = new Double_t[nlevels];
for (int i = 0; i < nlevels; i++) levels[i] = lmin + i * dl;
h->SetContour(nlevels, levels);
delete [] levels; // no longer needed
h->Draw("cont3 same");
#if 1 /* 0 or 1 */
TEllipse *e = new TEllipse(0., 0., 0.05); e->SetFillStyle(0); e->Draw();
#endif /* 0 or 1 */
gPad->Modified(); gPad->Update();
}