How can I replace division sign with slash in ticks of BarLegend












4












$begingroup$


I am plotting a Bar legend for the density plot using BarLegend. I got the desired bar legend but it has ticks in the form $frac{pi}{6},~frac{pi}{3},..$, I want them to be like $pi/6,~pi/3,...$ I want to write the division using slash. How can I do this in mathematica.



The code I am using is:



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}}, 
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks -> {π/6, π/3, π/2, 2 π/3}]









share|improve this question









New contributor




Parveen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$








  • 3




    $begingroup$
    Hi Parveen, welcome to MMA.SE! Please consider adding some code to your question - it really helps us help you if we can quickly reproduce your results. I'm pretty sure you want something like FormatType->StandardForm!
    $endgroup$
    – Carl Lange
    Jan 21 at 13:54
















4












$begingroup$


I am plotting a Bar legend for the density plot using BarLegend. I got the desired bar legend but it has ticks in the form $frac{pi}{6},~frac{pi}{3},..$, I want them to be like $pi/6,~pi/3,...$ I want to write the division using slash. How can I do this in mathematica.



The code I am using is:



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}}, 
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks -> {π/6, π/3, π/2, 2 π/3}]









share|improve this question









New contributor




Parveen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$








  • 3




    $begingroup$
    Hi Parveen, welcome to MMA.SE! Please consider adding some code to your question - it really helps us help you if we can quickly reproduce your results. I'm pretty sure you want something like FormatType->StandardForm!
    $endgroup$
    – Carl Lange
    Jan 21 at 13:54














4












4








4





$begingroup$


I am plotting a Bar legend for the density plot using BarLegend. I got the desired bar legend but it has ticks in the form $frac{pi}{6},~frac{pi}{3},..$, I want them to be like $pi/6,~pi/3,...$ I want to write the division using slash. How can I do this in mathematica.



The code I am using is:



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}}, 
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks -> {π/6, π/3, π/2, 2 π/3}]









share|improve this question









New contributor




Parveen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I am plotting a Bar legend for the density plot using BarLegend. I got the desired bar legend but it has ticks in the form $frac{pi}{6},~frac{pi}{3},..$, I want them to be like $pi/6,~pi/3,...$ I want to write the division using slash. How can I do this in mathematica.



The code I am using is:



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}}, 
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks -> {π/6, π/3, π/2, 2 π/3}]






plotting legending






share|improve this question









New contributor




Parveen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Parveen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Jan 21 at 16:03









Henrik Schumacher

51.2k469146




51.2k469146






New contributor




Parveen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Jan 21 at 13:18









ParveenParveen

355




355




New contributor




Parveen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Parveen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Parveen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 3




    $begingroup$
    Hi Parveen, welcome to MMA.SE! Please consider adding some code to your question - it really helps us help you if we can quickly reproduce your results. I'm pretty sure you want something like FormatType->StandardForm!
    $endgroup$
    – Carl Lange
    Jan 21 at 13:54














  • 3




    $begingroup$
    Hi Parveen, welcome to MMA.SE! Please consider adding some code to your question - it really helps us help you if we can quickly reproduce your results. I'm pretty sure you want something like FormatType->StandardForm!
    $endgroup$
    – Carl Lange
    Jan 21 at 13:54








3




3




$begingroup$
Hi Parveen, welcome to MMA.SE! Please consider adding some code to your question - it really helps us help you if we can quickly reproduce your results. I'm pretty sure you want something like FormatType->StandardForm!
$endgroup$
– Carl Lange
Jan 21 at 13:54




$begingroup$
Hi Parveen, welcome to MMA.SE! Please consider adding some code to your question - it really helps us help you if we can quickly reproduce your results. I'm pretty sure you want something like FormatType->StandardForm!
$endgroup$
– Carl Lange
Jan 21 at 13:54










2 Answers
2






active

oldest

votes


















5












$begingroup$

ticks = {π/6, π/3, π/2, 2 π/3};
BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}},
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
"Ticks" -> Transpose[{#, # /. Times[Rational[a_, b_], Pi] :> Row[{a Pi, "/", b}]} &@
ticks}],
LegendMarkerSize -> {30, 300}]


enter image description here



Alternatively, add the option "TickLabels":



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}}, 
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False, "Ticks" -> ticks,
"TickLabels" -> (ticks /. Times[Rational[a_, b_], Pi] :> Row[{a Pi, "/", b}]),
LegendMarkerSize -> {30, 300}]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Thanks for the answer. Something strange happened. I did copy and paste your code into my mathematica 11 and the ticks got interchanged. However I got the plot as you got but in my case $pi/6$ appears instead of $pi/2$. I don't know why!
    $endgroup$
    – Parveen
    Jan 21 at 14:51










  • $begingroup$
    @Parveen, it could be related to version/os. I am using version 11.3 (windows 10).
    $endgroup$
    – kglr
    Jan 21 at 14:57










  • $begingroup$
    Seems so. I am using ubuntu and mathematica 11
    $endgroup$
    – Parveen
    Jan 21 at 15:00










  • $begingroup$
    @Parveen, mathematica 11.3 or an earlier version?
    $endgroup$
    – kglr
    Jan 21 at 15:01










  • $begingroup$
    11.1.0.0 version
    $endgroup$
    – Parveen
    Jan 21 at 15:02



















4












$begingroup$

Something like this will work:



BarLegend[{
Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {[Pi]/6 - .1, 2 [Pi]/3 + .1}
},
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks -> ({#, InputForm@#} & /@ {[Pi]/6, [Pi]/3, [Pi]/2,
2 [Pi]/3})]


The idea is to pass a list like {{x1,label1},{x2,label2}...} to Ticks.



enter image description here



Since it seems like you know exactly what you want to put into your ticks, you could just put strings:



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {[Pi]/6 - .1, 
2 [Pi]/3 + .1}},
LabelStyle ->
Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks ->
Transpose[{{[Pi]/6, [Pi]/3, [Pi]/2, 2 [Pi]/3}, {"[Pi]/6",
"[Pi]/3", "[Pi]/2", "2[Pi]/3"}}]]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Seems correct but I want $pi$ instead of $Pi$ and the upper most tick should be $2pi/3$ instead of $2*Pi/3$. If you can modify it, then it would be a great help
    $endgroup$
    – Parveen
    Jan 21 at 14:53










  • $begingroup$
    @Parveen Check my latest edit.
    $endgroup$
    – Carl Lange
    Jan 21 at 15:10










  • $begingroup$
    Thanks. It works now
    $endgroup$
    – Parveen
    Jan 21 at 15:12










  • $begingroup$
    Consider marking the answer (or @kglr's answer, which is at least as good as mine) as accepted if it solved your problem!
    $endgroup$
    – Carl Lange
    Jan 21 at 15:22













Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Parveen is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f189940%2fhow-can-i-replace-division-sign-with-slash-in-ticks-of-barlegend%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









5












$begingroup$

ticks = {π/6, π/3, π/2, 2 π/3};
BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}},
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
"Ticks" -> Transpose[{#, # /. Times[Rational[a_, b_], Pi] :> Row[{a Pi, "/", b}]} &@
ticks}],
LegendMarkerSize -> {30, 300}]


enter image description here



Alternatively, add the option "TickLabels":



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}}, 
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False, "Ticks" -> ticks,
"TickLabels" -> (ticks /. Times[Rational[a_, b_], Pi] :> Row[{a Pi, "/", b}]),
LegendMarkerSize -> {30, 300}]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Thanks for the answer. Something strange happened. I did copy and paste your code into my mathematica 11 and the ticks got interchanged. However I got the plot as you got but in my case $pi/6$ appears instead of $pi/2$. I don't know why!
    $endgroup$
    – Parveen
    Jan 21 at 14:51










  • $begingroup$
    @Parveen, it could be related to version/os. I am using version 11.3 (windows 10).
    $endgroup$
    – kglr
    Jan 21 at 14:57










  • $begingroup$
    Seems so. I am using ubuntu and mathematica 11
    $endgroup$
    – Parveen
    Jan 21 at 15:00










  • $begingroup$
    @Parveen, mathematica 11.3 or an earlier version?
    $endgroup$
    – kglr
    Jan 21 at 15:01










  • $begingroup$
    11.1.0.0 version
    $endgroup$
    – Parveen
    Jan 21 at 15:02
















5












$begingroup$

ticks = {π/6, π/3, π/2, 2 π/3};
BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}},
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
"Ticks" -> Transpose[{#, # /. Times[Rational[a_, b_], Pi] :> Row[{a Pi, "/", b}]} &@
ticks}],
LegendMarkerSize -> {30, 300}]


enter image description here



Alternatively, add the option "TickLabels":



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}}, 
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False, "Ticks" -> ticks,
"TickLabels" -> (ticks /. Times[Rational[a_, b_], Pi] :> Row[{a Pi, "/", b}]),
LegendMarkerSize -> {30, 300}]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Thanks for the answer. Something strange happened. I did copy and paste your code into my mathematica 11 and the ticks got interchanged. However I got the plot as you got but in my case $pi/6$ appears instead of $pi/2$. I don't know why!
    $endgroup$
    – Parveen
    Jan 21 at 14:51










  • $begingroup$
    @Parveen, it could be related to version/os. I am using version 11.3 (windows 10).
    $endgroup$
    – kglr
    Jan 21 at 14:57










  • $begingroup$
    Seems so. I am using ubuntu and mathematica 11
    $endgroup$
    – Parveen
    Jan 21 at 15:00










  • $begingroup$
    @Parveen, mathematica 11.3 or an earlier version?
    $endgroup$
    – kglr
    Jan 21 at 15:01










  • $begingroup$
    11.1.0.0 version
    $endgroup$
    – Parveen
    Jan 21 at 15:02














5












5








5





$begingroup$

ticks = {π/6, π/3, π/2, 2 π/3};
BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}},
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
"Ticks" -> Transpose[{#, # /. Times[Rational[a_, b_], Pi] :> Row[{a Pi, "/", b}]} &@
ticks}],
LegendMarkerSize -> {30, 300}]


enter image description here



Alternatively, add the option "TickLabels":



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}}, 
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False, "Ticks" -> ticks,
"TickLabels" -> (ticks /. Times[Rational[a_, b_], Pi] :> Row[{a Pi, "/", b}]),
LegendMarkerSize -> {30, 300}]


enter image description here






share|improve this answer











$endgroup$



ticks = {π/6, π/3, π/2, 2 π/3};
BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}},
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
"Ticks" -> Transpose[{#, # /. Times[Rational[a_, b_], Pi] :> Row[{a Pi, "/", b}]} &@
ticks}],
LegendMarkerSize -> {30, 300}]


enter image description here



Alternatively, add the option "TickLabels":



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {π/6 - .1, 2 π/3 + .1}}, 
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False, "Ticks" -> ticks,
"TickLabels" -> (ticks /. Times[Rational[a_, b_], Pi] :> Row[{a Pi, "/", b}]),
LegendMarkerSize -> {30, 300}]


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 21 at 15:07

























answered Jan 21 at 14:42









kglrkglr

181k9200413




181k9200413












  • $begingroup$
    Thanks for the answer. Something strange happened. I did copy and paste your code into my mathematica 11 and the ticks got interchanged. However I got the plot as you got but in my case $pi/6$ appears instead of $pi/2$. I don't know why!
    $endgroup$
    – Parveen
    Jan 21 at 14:51










  • $begingroup$
    @Parveen, it could be related to version/os. I am using version 11.3 (windows 10).
    $endgroup$
    – kglr
    Jan 21 at 14:57










  • $begingroup$
    Seems so. I am using ubuntu and mathematica 11
    $endgroup$
    – Parveen
    Jan 21 at 15:00










  • $begingroup$
    @Parveen, mathematica 11.3 or an earlier version?
    $endgroup$
    – kglr
    Jan 21 at 15:01










  • $begingroup$
    11.1.0.0 version
    $endgroup$
    – Parveen
    Jan 21 at 15:02


















  • $begingroup$
    Thanks for the answer. Something strange happened. I did copy and paste your code into my mathematica 11 and the ticks got interchanged. However I got the plot as you got but in my case $pi/6$ appears instead of $pi/2$. I don't know why!
    $endgroup$
    – Parveen
    Jan 21 at 14:51










  • $begingroup$
    @Parveen, it could be related to version/os. I am using version 11.3 (windows 10).
    $endgroup$
    – kglr
    Jan 21 at 14:57










  • $begingroup$
    Seems so. I am using ubuntu and mathematica 11
    $endgroup$
    – Parveen
    Jan 21 at 15:00










  • $begingroup$
    @Parveen, mathematica 11.3 or an earlier version?
    $endgroup$
    – kglr
    Jan 21 at 15:01










  • $begingroup$
    11.1.0.0 version
    $endgroup$
    – Parveen
    Jan 21 at 15:02
















$begingroup$
Thanks for the answer. Something strange happened. I did copy and paste your code into my mathematica 11 and the ticks got interchanged. However I got the plot as you got but in my case $pi/6$ appears instead of $pi/2$. I don't know why!
$endgroup$
– Parveen
Jan 21 at 14:51




$begingroup$
Thanks for the answer. Something strange happened. I did copy and paste your code into my mathematica 11 and the ticks got interchanged. However I got the plot as you got but in my case $pi/6$ appears instead of $pi/2$. I don't know why!
$endgroup$
– Parveen
Jan 21 at 14:51












$begingroup$
@Parveen, it could be related to version/os. I am using version 11.3 (windows 10).
$endgroup$
– kglr
Jan 21 at 14:57




$begingroup$
@Parveen, it could be related to version/os. I am using version 11.3 (windows 10).
$endgroup$
– kglr
Jan 21 at 14:57












$begingroup$
Seems so. I am using ubuntu and mathematica 11
$endgroup$
– Parveen
Jan 21 at 15:00




$begingroup$
Seems so. I am using ubuntu and mathematica 11
$endgroup$
– Parveen
Jan 21 at 15:00












$begingroup$
@Parveen, mathematica 11.3 or an earlier version?
$endgroup$
– kglr
Jan 21 at 15:01




$begingroup$
@Parveen, mathematica 11.3 or an earlier version?
$endgroup$
– kglr
Jan 21 at 15:01












$begingroup$
11.1.0.0 version
$endgroup$
– Parveen
Jan 21 at 15:02




$begingroup$
11.1.0.0 version
$endgroup$
– Parveen
Jan 21 at 15:02











4












$begingroup$

Something like this will work:



BarLegend[{
Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {[Pi]/6 - .1, 2 [Pi]/3 + .1}
},
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks -> ({#, InputForm@#} & /@ {[Pi]/6, [Pi]/3, [Pi]/2,
2 [Pi]/3})]


The idea is to pass a list like {{x1,label1},{x2,label2}...} to Ticks.



enter image description here



Since it seems like you know exactly what you want to put into your ticks, you could just put strings:



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {[Pi]/6 - .1, 
2 [Pi]/3 + .1}},
LabelStyle ->
Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks ->
Transpose[{{[Pi]/6, [Pi]/3, [Pi]/2, 2 [Pi]/3}, {"[Pi]/6",
"[Pi]/3", "[Pi]/2", "2[Pi]/3"}}]]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Seems correct but I want $pi$ instead of $Pi$ and the upper most tick should be $2pi/3$ instead of $2*Pi/3$. If you can modify it, then it would be a great help
    $endgroup$
    – Parveen
    Jan 21 at 14:53










  • $begingroup$
    @Parveen Check my latest edit.
    $endgroup$
    – Carl Lange
    Jan 21 at 15:10










  • $begingroup$
    Thanks. It works now
    $endgroup$
    – Parveen
    Jan 21 at 15:12










  • $begingroup$
    Consider marking the answer (or @kglr's answer, which is at least as good as mine) as accepted if it solved your problem!
    $endgroup$
    – Carl Lange
    Jan 21 at 15:22


















4












$begingroup$

Something like this will work:



BarLegend[{
Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {[Pi]/6 - .1, 2 [Pi]/3 + .1}
},
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks -> ({#, InputForm@#} & /@ {[Pi]/6, [Pi]/3, [Pi]/2,
2 [Pi]/3})]


The idea is to pass a list like {{x1,label1},{x2,label2}...} to Ticks.



enter image description here



Since it seems like you know exactly what you want to put into your ticks, you could just put strings:



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {[Pi]/6 - .1, 
2 [Pi]/3 + .1}},
LabelStyle ->
Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks ->
Transpose[{{[Pi]/6, [Pi]/3, [Pi]/2, 2 [Pi]/3}, {"[Pi]/6",
"[Pi]/3", "[Pi]/2", "2[Pi]/3"}}]]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Seems correct but I want $pi$ instead of $Pi$ and the upper most tick should be $2pi/3$ instead of $2*Pi/3$. If you can modify it, then it would be a great help
    $endgroup$
    – Parveen
    Jan 21 at 14:53










  • $begingroup$
    @Parveen Check my latest edit.
    $endgroup$
    – Carl Lange
    Jan 21 at 15:10










  • $begingroup$
    Thanks. It works now
    $endgroup$
    – Parveen
    Jan 21 at 15:12










  • $begingroup$
    Consider marking the answer (or @kglr's answer, which is at least as good as mine) as accepted if it solved your problem!
    $endgroup$
    – Carl Lange
    Jan 21 at 15:22
















4












4








4





$begingroup$

Something like this will work:



BarLegend[{
Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {[Pi]/6 - .1, 2 [Pi]/3 + .1}
},
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks -> ({#, InputForm@#} & /@ {[Pi]/6, [Pi]/3, [Pi]/2,
2 [Pi]/3})]


The idea is to pass a list like {{x1,label1},{x2,label2}...} to Ticks.



enter image description here



Since it seems like you know exactly what you want to put into your ticks, you could just put strings:



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {[Pi]/6 - .1, 
2 [Pi]/3 + .1}},
LabelStyle ->
Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks ->
Transpose[{{[Pi]/6, [Pi]/3, [Pi]/2, 2 [Pi]/3}, {"[Pi]/6",
"[Pi]/3", "[Pi]/2", "2[Pi]/3"}}]]


enter image description here






share|improve this answer











$endgroup$



Something like this will work:



BarLegend[{
Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {[Pi]/6 - .1, 2 [Pi]/3 + .1}
},
LabelStyle -> Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks -> ({#, InputForm@#} & /@ {[Pi]/6, [Pi]/3, [Pi]/2,
2 [Pi]/3})]


The idea is to pass a list like {{x1,label1},{x2,label2}...} to Ticks.



enter image description here



Since it seems like you know exactly what you want to put into your ticks, you could just put strings:



BarLegend[{Hue[Rescale[#, {0, Pi}, {0, 1}]] &, {[Pi]/6 - .1, 
2 [Pi]/3 + .1}},
LabelStyle ->
Directive[Black, Bold, Medium, FontFamily -> "Courier"],
ColorFunctionScaling -> False,
Ticks ->
Transpose[{{[Pi]/6, [Pi]/3, [Pi]/2, 2 [Pi]/3}, {"[Pi]/6",
"[Pi]/3", "[Pi]/2", "2[Pi]/3"}}]]


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 21 at 15:10

























answered Jan 21 at 14:45









Carl LangeCarl Lange

3,3401731




3,3401731












  • $begingroup$
    Seems correct but I want $pi$ instead of $Pi$ and the upper most tick should be $2pi/3$ instead of $2*Pi/3$. If you can modify it, then it would be a great help
    $endgroup$
    – Parveen
    Jan 21 at 14:53










  • $begingroup$
    @Parveen Check my latest edit.
    $endgroup$
    – Carl Lange
    Jan 21 at 15:10










  • $begingroup$
    Thanks. It works now
    $endgroup$
    – Parveen
    Jan 21 at 15:12










  • $begingroup$
    Consider marking the answer (or @kglr's answer, which is at least as good as mine) as accepted if it solved your problem!
    $endgroup$
    – Carl Lange
    Jan 21 at 15:22




















  • $begingroup$
    Seems correct but I want $pi$ instead of $Pi$ and the upper most tick should be $2pi/3$ instead of $2*Pi/3$. If you can modify it, then it would be a great help
    $endgroup$
    – Parveen
    Jan 21 at 14:53










  • $begingroup$
    @Parveen Check my latest edit.
    $endgroup$
    – Carl Lange
    Jan 21 at 15:10










  • $begingroup$
    Thanks. It works now
    $endgroup$
    – Parveen
    Jan 21 at 15:12










  • $begingroup$
    Consider marking the answer (or @kglr's answer, which is at least as good as mine) as accepted if it solved your problem!
    $endgroup$
    – Carl Lange
    Jan 21 at 15:22


















$begingroup$
Seems correct but I want $pi$ instead of $Pi$ and the upper most tick should be $2pi/3$ instead of $2*Pi/3$. If you can modify it, then it would be a great help
$endgroup$
– Parveen
Jan 21 at 14:53




$begingroup$
Seems correct but I want $pi$ instead of $Pi$ and the upper most tick should be $2pi/3$ instead of $2*Pi/3$. If you can modify it, then it would be a great help
$endgroup$
– Parveen
Jan 21 at 14:53












$begingroup$
@Parveen Check my latest edit.
$endgroup$
– Carl Lange
Jan 21 at 15:10




$begingroup$
@Parveen Check my latest edit.
$endgroup$
– Carl Lange
Jan 21 at 15:10












$begingroup$
Thanks. It works now
$endgroup$
– Parveen
Jan 21 at 15:12




$begingroup$
Thanks. It works now
$endgroup$
– Parveen
Jan 21 at 15:12












$begingroup$
Consider marking the answer (or @kglr's answer, which is at least as good as mine) as accepted if it solved your problem!
$endgroup$
– Carl Lange
Jan 21 at 15:22






$begingroup$
Consider marking the answer (or @kglr's answer, which is at least as good as mine) as accepted if it solved your problem!
$endgroup$
– Carl Lange
Jan 21 at 15:22












Parveen is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Parveen is a new contributor. Be nice, and check out our Code of Conduct.













Parveen is a new contributor. Be nice, and check out our Code of Conduct.












Parveen is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Mathematica Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f189940%2fhow-can-i-replace-division-sign-with-slash-in-ticks-of-barlegend%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

An IMO inspired problem

Management

Has there ever been an instance of an active nuclear power plant within or near a war zone?