4
$\begingroup$

I have a contour plot as shown below. What I want is to have distinguishable contour labels i.e, here the value of the contours is not readable above 800 or so. How can I place the contour labels in some other positions so that I can mark the value for each of the contour lines? I have looked at already into these types of questions but mostly people have solved it for some functions whereas I have a data file.

enter image description here

I wrote the following code to generate the figure.

c = Import[ "/home/users/chakrtdm/Desktop/Gibbs/cal/analytic_debye/contour_\ plots/TD_DE_T/new.dat", "Table"]; ListContourPlot[c, Contours -> Range[100, 1900, 100], PlotRange -> {{-10, -100}, {0.01, 0.05}}, PlotRangeClipping -> False, FrameLabel -> {Style["X"], Style["Y"]}, Background -> White, AxesStyle -> Thick, FrameStyle -> Directive[Black, 15], BaseStyle -> {FontSize -> 12}, ColorFunction -> "Rainbow", ContourLabels -> (Text[Framed[#3], {#1, #2}, Background -> LightBlue] &), ContourStyle -> Opacity[10.0], ImageSize -> Automatic] 

The new.dat file can be found here.

$\endgroup$
8
  • 1
    $\begingroup$ …and where can people who are not you obtain new.dat? $\endgroup$ Commented Jul 25, 2016 at 13:33
  • $\begingroup$ @J.M.: I am extremely sorry, but it is a little bit big file. Is it somehow possible to attach that file rather copy & paste the entire data here? $\endgroup$ Commented Jul 25, 2016 at 13:38
  • $\begingroup$ @baban just Google "upload file" and pick your host. There are lots of free ones out there. $\endgroup$ Commented Jul 25, 2016 at 13:39
  • $\begingroup$ Here is the link for the data file. dropbox.com/s/5iluqr3jmfzb6oz/new.dat?dl=0 $\endgroup$ Commented Jul 25, 2016 at 13:43
  • $\begingroup$ why not use PlotLegends? $\endgroup$ Commented Jul 25, 2016 at 14:37

2 Answers 2

4
$\begingroup$

I found a very simple solution without thinking much about writing codes for placing contour labels. I find this is extremely helpful for the people who are not comfortable in writing explicit Mathematica codes like me.

The solution is here: Just select the plot and then double click on the plot and then double click on the text you want to make changes (please note that you legend box will be active now and you can do any kind of editing) to move and just drag it in your desired place.

If you want to write something new just type t on the plot and you can write anything you want. After this one has to click outside the graphics to see the changes. This simple method gives me enormous flexibility more specifically on legends. Now my plot looks as shown below which was what I exactly wanted.

enter image description here

$\endgroup$
2
  • $\begingroup$ What a ugly way! But it works brutally! :P $\endgroup$ Commented Aug 23, 2018 at 5:53
  • $\begingroup$ Holy crap, thank you. You can also ctrl-c ctrl-v labels if you have complicated curves and need multiple labels on the same curve! $\endgroup$ Commented Dec 5, 2019 at 9:50
1
$\begingroup$
c = Import["new.dat", "Table"]; ListContourPlot[c, Contours -> Range[100, 1900, 100], PlotRange -> {{-10, -100}, {0.01, 0.05}}, PlotRangeClipping -> False, FrameLabel -> {Style["X"], Style["Y"]}, Background -> White, AxesStyle -> Thick, FrameStyle -> Directive[Black, 15], BaseStyle -> {FontSize -> 12}, ColorFunction -> "Rainbow", PlotLegends -> Automatic] 

enter image description here

Alternative Approach

To make it clear I am going to do it with 5 contours.

conts = Range[200, 2000, 400]; ListContourPlot[c, PlotRange -> {{-10, -100}, {0.01, 0.05}}, ColorFunction -> "Rainbow", PlotLegends -> Automatic, Contours -> conts, ContourLabels -> All, BaseStyle -> 12] 

enter image description here

Now you choose a position for your labels

pos = Table[{-60, j}, {j, 0.02, 0.04, 0.005}] 

and a nearby reference point on each contour

ref = {{-11, 0.04}, {-11, 0.02}, {-20, 0.04}, {-40, 0.03}, {-100, 0.03}}; 

And then

plot = ListContourPlot[c, PlotRange -> {{-10, -100}, {0.01, 0.05}}, Contours -> conts, ColorFunction -> "Rainbow"]; lines = Cases[plot // Normal, Line[x_] :> x, Infinity]; cen = Nearest[lines[[#]], ref[[#]]][[1]] & /@ Range[nc]; Show[plot, FrameLabel -> {Style["X"], Style["Y"]}, Background -> White, AxesStyle -> Thick, FrameStyle -> Directive[Black, 15], BaseStyle -> {FontSize -> 12}, Epilog -> ({Arrow[{pos[[#]], cen[[#]]}], Text[Style[conts[[nc - # + 1]], 16, Background -> LightBlue], pos[[#]]]} & /@ Range[1, nc])] 

enter image description here

$\endgroup$
5
  • $\begingroup$ I think I already have it. My question was regarding the contour labels .What I want is to have the contour labels clearly visible for each of the contour lines. Bar is ok but if you look at my picture I have contour values written in framed texts. But they were really close for above 800 values and I want to tag them in a different way so that each of those can be easily seen. $\endgroup$ Commented Jul 25, 2016 at 15:02
  • $\begingroup$ Writing individual labels might be problematic if you have so many contours. And for MMA8 check this. $\endgroup$ Commented Jul 25, 2016 at 15:13
  • $\begingroup$ Ya Thanks! So, then there is no way where I can desirably place my contour labels in the contour plot? $\endgroup$ Commented Jul 25, 2016 at 15:17
  • $\begingroup$ @baban, check my new answer. $\endgroup$ Commented Jul 25, 2016 at 16:03
  • $\begingroup$ Great! This is nice. Thank you! $\endgroup$ Commented Jul 25, 2016 at 16:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.