How can I add a title to each subplot in an ImageGrid and a single xlabel/ylabel for the entire figure?
Date : March 29 2020, 07:55 AM
seems to work fine If you want a title for each subplot, you can just use the title command for that axis. Where you have: title('Subject {0} in-Trial Gaze'.format(subnum))
gridax.set_title('Subject {0} in-Trial Gaze'.format(subnum))
|
title in subplot and xlabel
Tag : matlab , By : noboruwatanabe
Date : March 29 2020, 07:55 AM
I wish this helpful for you In general if you return handles to your figures/axes when you create them, you can tailor each piece by passing that handle as the first argument to a plot modifying function. So if you did a1 = subplot(2,1,1);
a2 = subplot(2,1,2);
xlabel(a1, 'title here', 'FontSize', 12)
xlabel(a2, 'other title', 'FontWeight', 'bold')
|
MATLAB: Trying to add shared xlabel,ylabel in 3x2 subplot
Date : March 29 2020, 07:55 AM
around this issue You could use mtit to create an invisible axes around the subplots. mtit returns the handle to that axes, for which you can then create xlabel and ylabel. Example: % create sample data
my_data = arrayfun(@(x)rand(10, 2) + repmat([x, 0], 10, 1), 1:6, 'UniformOutput', 0);
figure;
clf
ah = gobjects(6, 1); % use zeros if using an old version of MATLAB
% plot data
for ii = 1:6
ah(ii) = subplot(3, 2, ii);
plot(1:10, my_data{ii}(:, 1));
hold on
plot(1:10, my_data{ii}(:, 2));
end
% link axes to have same ranges
max_data = max(cellfun(@(x) max(x(:)), my_data));
min_data = min(cellfun(@(x) min(x(:)), my_data));
linkaxes(ah, 'xy')
ylim([min_data, max_data])
% Create invisible large axes with title (title could be empty)
hh = mtit('Cool experiment');
%set(gcf, 'currentAxes', hh.ah)
% make ylabels
ylh = ylabel(hh.ah, 'Temperature [°C]');
set(ylh, 'Visible', 'On')
xlh = xlabel(hh.ah, 'x label');
set(xlh, 'Visible', 'On')
|
Matplotlib: how to add xlabel, title to each subplot
Tag : python , By : user179445
Date : March 29 2020, 07:55 AM
around this issue When using the matplotlib object-oriented interface, the correct commands to use are ax.set_xlabel and ax.set_ylabel. (Compare these to plt.xlabel, etc., for the state-machine interface).
|
xlabel for first subplot pop up as a list
Date : March 29 2020, 07:55 AM
I wish this helpful for you Usually, because you use sharex, you would not expect any labels below the first bar plot. So what you see there is the list set by axarr[i].set_xlabel(x). Now x isn't really used at this place in the code; it is the list you get via x, y = get_val_from_dict(data, n). I suppose you simply want to remove the line axarr[i].set_xlabel(x) from your code, or replace it with something more useful, axarr[i].set_xlabel("My cool categories")
import matplotlib.pyplot as plt
x1 = [u'fast_food', u'school', u'bar', u'beauty', u'hairdresser', u'park', u'hotel', u'kiosk', u'pub', u'nightclub', u'supermarket', u'restaurant', u'bakery', u'pharmacy', u'doctors', u'fitness_centre', u'cafe', u'bank', u'clothes']
y1 = [0.08, 0.03, 0.03, 0.01, 0.05, 0.03, 0.19, 0.12, 0.04, 0.01, 0.01, 0.25, 0.03, 0.01, 0.02, 0.02, 0.05, 0.01, 0.02]
x2 = [u'fast_food', u'school', u'bar', u'jewelry', u'beauty', u'hairdresser', u'shoes', u'park', u'museum', u'restaurant', u'kiosk', u'supermarket', u'pharmacy', u'bakery', u'greengrocer', u'cafe', u'bank', u'clothes']
y2 = [0.03, 0.03, 0.03, 0.03, 0.03, 0.15, 0.03, 0.09, 0.03, 0.21, 0.06, 0.03, 0.03, 0.06, 0.03, 0.06, 0.06, 0.03]
x_all = [x1,x2]
y_all = [y1,y2]
name_ = ["A", "B"]
fig, axarr = plt.subplots(len(x_all), sharey='row')
for i in range(len(x_all)):
axarr[i].set_title(label ="%s" %(name_[i]))
axarr[i].bar(x_all[i], y_all[i])
axarr[i].tick_params(axis='both', which='both')
axarr[i].set_xlabel("My cool categories")
axarr[i].set_xticklabels(x_all[i], rotation=90)
fig.tight_layout()
plt.show()
|