Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting certain tick labels in boldface (but not all of them)?

In MATLAB I have a graph with some tick labels. I'd like to visually emphasize a few of these labels, but not all of them. Is there a way to only put SOME tick labels in boldface?

like image 599
dB' Avatar asked Feb 07 '12 01:02

dB'


People also ask

How do I bold a tick label?

The following will make the XTickLabels bold: fig = figure(1); ax = axes; % or: ax = gca; plot(rand(10)); ax.

How do I bold a tick label in Python?

The command fontweight='bold' can be used to make a textbox or label in figure bold.

How do I bold a tick in Matplotlib?

You can get around this by adding the correct commands to the LaTeX preamble, using rcParams . Specifcally, you need to use \boldmath to get the correct weight, and \usepackage{sfmath} to get sans-serif font.

How do you bold a tick in Matlab?

Direct link to this answer xlabel('X Axis', 'FontSize', 9, 'FontWeight', 'bold'); % Make the x axis (line) and tick marks have a line width of 2 and color red.


2 Answers

Though I can't tell if it wasn't possible in the past, but nowadays (at least from R2014b) one could just use tex markup:

plot(0:10,0:10);
h = gca;
h.XTickLabel = {'\bf \color{red} 0','2','\bf 4','6','\bf \color{red} 8','10',}

enter image description here

like image 149
Robert Seifert Avatar answered Oct 20 '22 00:10

Robert Seifert


Tick labels are not individual objects. They belong to axes and their properties determined by axes.

What you can do is to remove tick labels and replace them with text objects. In this case you can control the text properties.

plot(magic(5))
xticks = get(gca,'XTick'); %# x tick positions
xlabels = cellstr(get(gca,'XTickLabel')); %# get the x tick labels as cell array of strings
set(gca,'XTickLabel',[]) %# remove the labels from axes
n = numel(xlabels);
yl = ylim;
idx1 = 1:2:n; %# 1st set of ticks
idx2 = 2:2:n; %# 2nd set
t1 = text(xticks(idx1),repmat(yl(1),numel(idx1),1), xlabels(idx1), ...
    'HorizontalAlignment','center','VerticalAlignment','top');
t2 = text(xticks(idx2),repmat(yl(1),numel(idx2),1), xlabels(idx2), ...
    'HorizontalAlignment','center','VerticalAlignment','top');
set(t2,'FontWeight','bold') %# make the 2nd set bold

Bold ticks example

like image 33
yuk Avatar answered Oct 19 '22 23:10

yuk