Fixing the width of a subplot in matplotlib - python

I'm trying to fix the width of one of the subplots to a fixed value. The issue comes from the fact that I'm combining ax.imshow() and ax.plot in the same column of plots and I'd like my plots to have the same width so that they line up on both sides, since they should share the x axis. to complicate things, the ax.imshow() also has a colorbar, which I introduced with ax.figure.colorbar() and that needs to be ignored when talking about the width of the plot. So far the only way I managed to make it work is by inserting values for ax.set_aspect() manually, but it takes a long time to get it right by trial and error.
I won't bore you with the details, especially because the code is a bit too long, but I'll include it here for completeness, hoping that it won't cause too much confusion. You won't be able to run it yourself unfortunately, since I'm only including the plotting part of the code.
Thanks in advance for your help.
df_spec = pd.read_csv(path + spec_name, header=spec_header, skipfooter=3)
df_spec['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(df_spec['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'], format = '%Y-%m-%dT%H:%M:%S.%fZ')
dates_list = df_spec['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'].to_list()
x_lims_ = [dates_list[0].timestamp(), dates_list[-1].timestamp()]
x_lims = list(map(dt.datetime.fromtimestamp, x_lims_))
x_lims = mdates.date2num(x_lims)
y_lims0 = np.linspace(1075, 13825, 100)
y_lims1 = np.linspace(20, 1040, 100)
y_lims2 = np.linspace(4, 245, 100)
#plt.FuncFormatter
def fake_log(x, pos):
'The two args are the value and tick position'
return round(10**x) #r'$10^{%.2f}$' % (x)
df_spec = df_spec.set_index('EPOCH_yyyy-mm-ddThh:mm:ss.sssZ')
df_spec = df_spec[df_spec.columns[::-1]].T
df_spec0 = df_spec.iloc[353:-1, :]
df_spec1 = df_spec.iloc[95:353, :]
df_spec2 = df_spec.iloc[0:95, :]
date_format = mdates.DateFormatter('%H:%M:%S')
locator = mdates.HourLocator([4, 5, 6, 7, 8, 9])
fig, ax = plt.subplots(6, 1, figsize=(15,20))
for a in ax:
a.set_anchor('W')
for a in ax:
a.patch.set_facecolor('black')
im = ax[0].imshow(df_spec0, norm=colors.LogNorm(), cmap=cm.inferno, extent = [x_lims[0], x_lims[1], np.log10(y_lims0[0]), np.log10(y_lims0[-1])], aspect='auto')
ax[0].figure.colorbar(im, ax=ax[0])
ax[0].xaxis.set(major_formatter=date_format, major_locator=locator)
ax[0].tick_params(bottom = False)
ax[0].set_xticks([])
ax[0].yaxis.set_major_formatter(fake_log)
ax[0].yaxis.set_major_locator(MaxNLocator(5))
ax[0].set_yticks(np.log10(np.array([2000, 5000, 10000])))
im = ax[1].imshow(df_spec1, norm=colors.LogNorm(), cmap=cm.inferno, extent = [x_lims[0], x_lims[1], np.log10(y_lims1[0]), np.log10(y_lims1[-1])], aspect='auto')
ax[1].figure.colorbar(im, ax=ax[1])
ax[1].xaxis.set(major_formatter=date_format, major_locator=locator)
ax[1].tick_params(bottom = False)
ax[1].set_xticks([])
ax[1].yaxis.set_major_formatter(fake_log)
ax[1].yaxis.set_major_locator(MaxNLocator(5))
ax[1].set_yticks(np.log10(np.array([20, 50, 100, 200, 500, 1000])))
im = ax[2].imshow(df_spec2, norm=colors.LogNorm(), cmap=cm.inferno, extent = [x_lims[0], x_lims[1], np.log10(y_lims2[0]), np.log10(y_lims2[-1])], aspect='auto')
ax[2].figure.colorbar(im, ax=ax[2])
ax[2].xaxis.set(major_formatter=date_format, major_locator=locator)
ax[2].tick_params(bottom = False)
ax[2].set_xticks([])
ax[2].yaxis.set_major_formatter(fake_log)
ax[2].yaxis.set_major_locator(MaxNLocator(5))
ax[2].set_yticks(np.log10(np.array([10, 20, 50, 100, 200])))
#second set of images
df1 = pd.read_csv(path + f1_name, header=f1_header, skipfooter=3)
df1['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(df1['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'], format = '%Y-%m-%dT%H:%M:%S.%fZ')
df2 = pd.read_csv(path + f2_name, header=f2_header, skipfooter=3)
df2['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(df2['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'], format = '%Y-%m-%dT%H:%M:%S.%fZ')
df3 = pd.read_csv(path + f3_name, header=f3_header, skipfooter=3)
df3['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'] = pd.to_datetime(df3['EPOCH_yyyy-mm-ddThh:mm:ss.sssZ'], format = '%Y-%m-%dT%H:%M:%S.%fZ')
i1, i2, i3 = 1, 1, 1
energies1 = [27, 40, 66, 108, 181, 310, 517]
energies2 = list(reversed(list(np.array([6, 7, 9, 13, 18, 27, 41, 65, 103, 164, 264, 426, 689, 1113])*1e-3)))
energies3 = list(reversed([0.137, 0.2, 0.29, 0.43, 0.64, 0.92, 1.34, 1.95, 2.85, 4.16, 6.08, 6.87, 12.97, 18.9, 27]))
#fig, ax = plt.subplots(3, 1, figsize=(10,10))
while i1 < 8 :
ax[5].plot(df1.iloc[:, 0], df1.iloc[:, i1], c=cm.rainbow([50*i1]))
ax[5].vlines(arrival_time(energies1[i1-1]), 0,0.3, color=cm.rainbow([50*i1]), label = str(energies1[i1-1]) + ' keV')
ax[5].set_xlim(df3.iloc[0, 0], df3.iloc[-1, 0])
ax[5].set_yscale("log")
plt.gcf().autofmt_xdate()
i1 += 1
while i2 < 15 :
ax[3].plot(df2.iloc[:, 0], df2.iloc[:, i2], c=cm.rainbow([20*i2]), label = str(round(energies2[i2-1]*1e3)) + ' eV')
ax[3].vlines(arrival_time(energies2[i2-1]), 0,4e8, color=cm.rainbow([20*i2]))
ax[3].set_xlim(df3.iloc[0, 0], df3.iloc[-1, 0])
ax[3].set_yscale("log")
i2 += 1
while i3 < 15 :
ax[4].plot(df3.iloc[:, 0], df3.iloc[:, i3], c=cm.rainbow([20*i3]), label = str(round(energies3[i3-1]*1e3)) + ' eV')
ax[4].vlines(arrival_time(energies3[i3-1]), 0,1e5, color=cm.rainbow([20*i3]))
ax[4].set_xlim(df3.iloc[0, 0], df3.iloc[-1, 0])
ax[4].set_yscale("log")
i3 += 1
fig.tight_layout()
# bigger aspect ratio means shorter plot (and viceversa)
ax[3].set_aspect(0.00574) # 2002-04-25: 0.00646
ax[4].set_aspect(0.004899) # 2002-04-25: 0.00684
ax[5].set_aspect(0.006865) # 2002-04-25: 0.01415
ax[4].set_ylim(None, 8e4)
ax[3].set_ylim(top=3e8)
ax[5].set_ylim(top=0.2)
ax[3].legend(loc='upper left', bbox_to_anchor=(1, 1),fontsize = 11)
ax[4].legend(loc='upper left', bbox_to_anchor=(1, 1),fontsize = 11)
ax[5].legend(loc='upper left', bbox_to_anchor=(1, 1),fontsize = 11)
ax[5].set_xlabel('UT', fontsize = 20)
ax[1].set_ylabel('Frequency [kHz]', fontsize = 20)
ax[4].set_ylabel('Eletrons $cm^{-2} ster^{-1} s^{-1} eV^{-1}$', fontsize = 20)
plt.show()
plt.savefig(path + "Spec_Plot_2002_04_25", bbox_inches='tight')

You may want to try layout='compressed':
fig, axs = plt.subplots(2, 1, sharex=True, figsize=(10, 4),
layout='compressed')
x = np.arange(10)
y = np.random.randn(10)
axs[0].plot(x, y)
im = axs[1].imshow(np.random.randn(10, 10), extent=[0, 10, 0, 10])
fig.colorbar(im, ax=axs[1], shrink=0.5)
plt.show()

Related

How to properly set labels in contourf subplots?

I am trying to get rid of these purple points on the picture below. Here is my code:
p_values = [0., 0.05, 0.25, 0.5, 1, 1.5, 2, 5, 10, np.inf]
xx, yy = np.meshgrid(np.linspace(-3, 3, num = 101),
np.linspace(-3, 3, num = 101))
fig, axes = plt.subplots(ncols = (len(p_values) + 1) // 2,
nrows = 2, figsize = (16, 7))
for p, ax in zip(p_values, axes.flat):
### BEGIN Solution (do not delete this comment)
z = np.linalg.norm([xx, yy], ord = p, axis = 0)
ax.contourf(yy, xx, z, 25, cmap = 'coolwarm')
ax.contour(yy, xx, z, [1], colors = 'fuchsia', linewidths = 3)
ax.set_title(f'p = {p}')
ax.legend([f'$x: |x|_{{{p}}} = 1$']);
### END Solution (do not delete this comment)
plt.show()
Which parameters should be specified in ax.legend() in order to plot the graph clear.
You could create the legend using an explicit handle. In this case the fuchsia colored line is stored as the last element of ax.collections. Creating the legend with only labels, when there were no "handles with labels" set, could be the cause of the weird purple dots.
import matplotlib.pyplot as plt
import numpy as np
p_values = [0., 0.05, 0.25, 0.5, 1, 1.5, 2, 5, 10, np.inf]
xx, yy = np.meshgrid(np.linspace(-3, 3, num=101),
np.linspace(-3, 3, num=101))
fig, axes = plt.subplots(ncols=(len(p_values) + 1) // 2,
nrows=2, figsize=(16, 7))
cmap = plt.get_cmap('magma').copy()
cmap.set_extremes(over='green', under='black', bad='turquoise')
for p, ax in zip(p_values, axes.flat):
### BEGIN Solution (do not delete this comment)
z = np.linalg.norm([xx, yy], ord=p, axis=0)
cnt = ax.contourf(yy, xx, z, 25, cmap='coolwarm')
ax.contour(yy, xx, z, [1], colors='fuchsia', linewidths=3)
ax.set_title(f'p = {p}')
ax.legend(handles=[ax.collections[-1]], labels=[f'$x: |x|_{{{p}}} = 1$'])
plt.colorbar(cnt, ax=ax)
### END Solution (do not delete this comment)
plt.tight_layout()
plt.show()

stacked barplot from arrays of different lengths

I am working on an energy balance and I am currently creating a barplot. I want to compare the generation and consumption of electricity over the years. Therefore I have 2 stacked bars for each year. This is how far I got:
import matplotlib.pyplot as plt
import numpy as np
generation_2020 = [20, 30, 40, 20, 10]
consumption_2020 = [50,50]
import_2020 = 20
if import_2020 >0:
generation_2020 = np.append(generation_2020, import_2020)
else:
consumption_2020 = np.insert(consumption_2020, 0, import_2020*-1, axis=0)
generation_2025 = np.array([20, 20, 20, 20, 10])
consumption_2025 = np.array([50,50])
import_2025 = -10
if import_2025 >0:
generation_2025 = np.append(generation_2025, import_2025)
else:
consumption_2025 = np.insert(consumption_2025, 0, import_2025*-1, axis=0)
data = np.array([generation_2020, generation_2025])
data2 = np.array([consumption_2020, consumption_2025])
label_data = ['renewables','gas','cole', 'storage', 'nuclear', 'import', 'consumption', 'storage']
x2 = ['2020', '2025']
x3 = ['Erzeugung' , '\n\n\n\n\n\n2020', 'Verbrauch', 'Erzeugung' , '\n\n\n\n\n\n2025', 'Verbrauch']
x_pos = np.arange(len(x2))
width = 0.2
x = list()
for i in x_pos:
x.extend([i-width, i, i+width])
fig, ax = plt.subplots()
for i in range(data.shape[1]):
bottom = np.sum(data[:, 0:i], axis=1)
ax.bar(x_pos - width, data[:, i], bottom=bottom, width=width, label=f"label {i}")
for i in range(data2.shape[1]):
bottom = np.sum(data2[:, 0:i], axis=1)
ax.bar(x_pos+ width, data2[:, i], bottom=bottom, width=width, label=f"label {i}")
ax.set_ylabel('[TWh]')
ax.set_xticks(x)
ax.set_xticklabels(x3)
ax.tick_params(axis='x', which='both',length=0, labelsize = 10)
for label in ax.get_xmajorticklabels():
if 'u' in label.get_text(): label.set_rotation(90)
ax.margins(y=0.1) # some extra padding to place the bar labels
plt.legend(label_data, bbox_to_anchor=(1, 1))
fig.tight_layout()
plt.show()
This works if both import_2020 and import_2025 are either both negative or both positive. If one is negative and the other is positive it doesnt.
This is the error message I get:
for i in range(data.shape[1]):
IndexError: tuple index out of range
The problem is that generation_2020 and generation_2025 dont have the same length. One has 5 entries and the other 6. Does someone have an Idea how to solve this?

Applying different color to points equal to zero in matplotlib

I'm trying, so far without success, to establish a fixed color to points equal to zero in matplotlib. As can be seen in the figure below, the points inside the circles are almost invisible since their color are similar to the ones applied to the points equal to zero. Is there some kind of flag that I'm missing or should I create a new array of colors instead of using the predefined colormaps?
def plot_scatter_x_y(**options):
label_format_sci = options.get('label_format_sci')
xaxis = options.get('xaxis')
yaxis = options.get('yaxis')
zaxis = options.get('zaxis')
xaxis_label = options.get('xaxis_label')
yaxis_label = options.get('yaxis_label')
zaxis_label = options.get('zaxis_label')
title = options.get('title', 'Fig. title')
bullet_size = options.get('bullet_size')
fig = plt.figure(figsize=(2, 2))
ax = fig.add_subplot(111)
cmap_range = yaxis
if zaxis:
cmap_range = zaxis
plt.axis('equal')
p = plt.scatter(xaxis, yaxis, c=cmap_range, cmap=plt.cm.get_cmap(options.get('colormap'), options.get('colormap_range')), s=bullet_size, edgecolor='black', linewidths=0, marker = 's')
if label_format_sci:
plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
plt.title(title)
plt.xlabel(xaxis_label)
plt.ylabel(yaxis_label)
plt.xlim(min(xaxis), max(xaxis))
plt.ylim(min(yaxis), max(yaxis))
plt.xticks(np.linspace(min(xaxis), max(xaxis), 5))
plt.yticks(np.linspace(min(yaxis), max(yaxis), 5))
#legend
if zaxis:
cbar = plt.colorbar(p, format='%.0e', orientation='horizontal')#, pad=0.1)
cbar.set_label(zaxis_label)#, rotation=90, labelpad=0)
cbar.set_ticks(np.linspace(min(zaxis), max(zaxis), 5))
fig.savefig(f"{options.get('path_fig')}.pdf", bbox_inches='tight', pad_inches=0)
plt.close('all')
# test
xaxis = [0, 1, 2, 3]
yaxis = [0, 1, 2, 3]
zaxis = [0, 1, 5, 0]
xaxis_label = "X-axis"
xaxis_label = "Y-axis"
title = "Title"
plot_scatter_x_y(xaxis=xaxis, xaxis_label=xaxis_label, yaxis=yaxis, yaxis_label=yaxis_label, title=title, path_fig=f'figure', colormap='inferno', colormap_range=1, label_format_sci=True)
I manage to do with a new array of colors. It seems like overkill for such a simple thing.
def plot_scatter_x_y(**options):
label_format_sci = options.get('label_format_sci')
xaxis = options.get('xaxis')
yaxis = options.get('yaxis')
zaxis = options.get('zaxis')
xaxis_label = options.get('xaxis_label')
yaxis_label = options.get('yaxis_label')
zaxis_label = options.get('zaxis_label')
title = options.get('title', 'Fig. title')
bullet_size = options.get('bullet_size')
colormap = options.get('colormap')
colormap_range = options.get('colormap_range')
original_cmap = cm.get_cmap(colormap, colormap_range)
newcolors = original_cmap(np.linspace(0, 1, 256))
zero_color = np.array([230/256, 230/256, 230/256, 1])
newcolors[0, :] = zero_color
newcmp = ListedColormap(newcolors)
fig = plt.figure(figsize=(2, 2))
ax = fig.add_subplot(111)
cmap_range = yaxis
if zaxis:
cmap_range = zaxis
plt.axis('equal')
p = plt.scatter(xaxis, yaxis, c=cmap_range, cmap=plt.cm.get_cmap(newcmp, colormap_range), s=bullet_size, edgecolor='black', linewidths=0, marker = 's')
if label_format_sci:
plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
plt.title(title)
plt.xlabel(xaxis_label)
plt.ylabel(yaxis_label)
plt.xlim(min(xaxis), max(xaxis))
plt.ylim(min(yaxis), max(yaxis))
plt.xticks(np.linspace(min(xaxis), max(xaxis), 5))
plt.yticks(np.linspace(min(yaxis), max(yaxis), 5))
#legend
if zaxis:
cbar = plt.colorbar(p, format='%.0e', orientation='horizontal')#, pad=0.1)
cbar.set_label(zaxis_label)#, rotation=90, labelpad=0)
cbar.set_ticks(np.linspace(min(zaxis), max(zaxis), 5))
fig.savefig(f"{options.get('path_fig')}.pdf", bbox_inches='tight', pad_inches=0)
plt.close('all')
# test
xaxis = [0, 1, 2, 3]
yaxis = [0, 1, 2, 3]
zaxis = [0, 1, 5, 0]
xaxis_label = "X-axis"
xaxis_label = "Y-axis"
title = "Title"
plot_scatter_x_y(xaxis=xaxis, xaxis_label=xaxis_label, yaxis=yaxis, yaxis_label=yaxis_label, title=title, path_fig=f'figure', colormap='inferno', colormap_range=1, label_format_sci=True)

Grouped Bar Plot with Pattern Fill using Python and Matplotlib

I found the following barplot on the following website: http://ndaratha.blogspot.com/2015/03/grouped-bar-plot
According to the website, it corresponds to the following code
import matplotlib.pyplot as plt
# Input data; groupwise
green_data = [16, 23, 22, 21, 13, 11, 18, 15]
blue_data = [ 3, 3, 0, 0, 5, 5, 3, 3]
red_data = [ 6, 6, 6, 0, 0, 0, 0, 0]
black_data = [25, 32, 28, 21, 18, 16, 21, 18]
labels = ['XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII']
# Setting the positions and width for the bars
pos = list(range(len(green_data)))
width = 0.15 # the width of a bar
# Plotting the bars
fig, ax = plt.subplots(figsize=(10,6))
bar1=plt.bar(pos, green_data, width,
alpha=0.5,
color='w',
hatch='x', # this one defines the fill pattern
label=labels[0])
plt.bar([p + width for p in pos], blue_data, width,
alpha=0.5,
color='w',
hatch='o',
label=labels[1])
plt.bar([p + width*2 for p in pos], red_data, width,
alpha=0.5,
color='k',
hatch='',
label=labels[2])
plt.bar([p + width*3 for p in pos], black_data, width,
alpha=0.5,
color='w',hatch='*',
label=labels[3])
# Setting axis labels and ticks
ax.set_ylabel('Number of Switching')
ax.set_xlabel('Strategy')
ax.set_title('Grouped bar plot')
ax.set_xticks([p + 1.5 * width for p in pos])
ax.set_xticklabels(labels)
# Setting the x-axis and y-axis limits
plt.xlim(min(pos)-width, max(pos)+width*5)
plt.ylim([0, max(green_data + blue_data + red_data) * 1.5])
# Adding the legend and showing the plot
plt.legend(['OLTC', 'SVC', 'SC', 'OLTC+SC+SVC'], loc='upper right')
plt.grid()
plt.show()
But when I try running the code, I get the following output
Does anyone know what I'm doing wrong or what I should do to get the desired output?
You need to add edgecolor = "k" in your plt.bar() code which gives black colors to the bar edges, and you can get the barplot you want.
When you add edgecolor = "k", code is as follows,
import matplotlib.pyplot as plt
# Input data; groupwise
green_data = [16, 23, 22, 21, 13, 11, 18, 15]
blue_data = [ 3, 3, 0, 0, 5, 5, 3, 3]
red_data = [ 6, 6, 6, 0, 0, 0, 0, 0]
black_data = [25, 32, 28, 21, 18, 16, 21, 18]
labels = ['XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII']
# Setting the positions and width for the bars
pos = list(range(len(green_data)))
width = 0.15 # the width of a bar
# Plotting the bars
fig, ax = plt.subplots(figsize=(10,6))
bar1=plt.bar(pos, green_data, width,
alpha=0.5,
color='w',
hatch='x', # this one defines the fill pattern
label=labels[0],edgecolor='black')
plt.bar([p + width for p in pos], blue_data, width,
alpha=0.5,
color='w',
hatch='o',
label=labels[1],edgecolor='black')
plt.bar([p + width*2 for p in pos], red_data, width,
alpha=0.5,
color='k',
hatch='',
label=labels[2],edgecolor='black')
plt.bar([p + width*3 for p in pos], black_data, width,
alpha=0.5,
color='w',hatch='*',
label=labels[3],edgecolor='black')
# Setting axis labels and ticks
ax.set_ylabel('Number of Switching')
ax.set_xlabel('Strategy')
ax.set_title('Grouped bar plot')
ax.set_xticks([p + 1.5 * width for p in pos])
ax.set_xticklabels(labels)
# Setting the x-axis and y-axis limits
plt.xlim(min(pos)-width, max(pos)+width*5)
plt.ylim([0, max(green_data + blue_data + red_data) * 1.5])
# Adding the legend and showing the plot
plt.legend(['OLTC', 'SVC', 'SC', 'OLTC+SC+SVC'], loc='upper right')
plt.grid()
plt.show()

subplots in matplotlib using histogram

diff = [[10,20,30],[40,50,60],[70,80,90]]
comp = ["foo","bar","baz"]
fig,ax = plt.subplots()
for foo in range(0, len(diff)):
x = [diff[foo]]
name = comp
color = ['0.1', '0.2', '0.3']
label = ['1000000','1200000', '1400000']
y = zip(*x)
pos = np.arange(len(x))
width = 1. / (1 + len(x))
fig = plt.subplot(3,1,foo)
for idx, (serie, color,label) in enumerate(zip(y, color,label)):
ax.bar(pos + idx * width, serie, width, color=color,label=label)
fig = plt.gcf()
fig.set_size_inches(28.5,10.5)
ax.set_xticks(pos + 1.5*width)
plt.ylabel(name[foo])
ax.set_xticklabels(comp)
ax.legend()
plt.gray()
plt.savefig("file" + '.jpg', bbox_inches='tight', pad_inches=0.5,dpi=100)
plt.clf()
I want to subplot foo bar and baz. But when I try to do that using the above code. The data is not being displayed on the graph. Any idea why?
You are replacing the first fig when you call subplot inside the loop, here is a fixed version. See that ax returned by subplots is a np.ndarray, so you have to give an index ax[foo] to obtain the AxesSubplot object.
diff = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]
comp = ["foo", "bar", "baz"]
fig, ax = plt.subplots(3, 1)
for foo in range(0, len(diff)):
x = [diff[foo]]
name = comp
color = ['0.1', '0.2', '0.3']
label = ['1000000', '1200000', '1400000']
y = zip(*x)
pos = np.arange(len(x))
width = 1. / (1 + len(x))
for idx, (serie, color,label) in enumerate(zip(y, color,label)):
ax[foo].bar(pos + idx * width, serie, width, color=color,label=label)
fig.set_size_inches(28.5, 10.5)
ax[foo].set_xticks(pos + 1.5*width)
plt.ylabel(name[foo])
ax[foo].set_xticklabels(comp)
ax[foo].legend()
plt.gray()
fig.savefig("file" + '.jpg', bbox_inches='tight', pad_inches=0.5, dpi=100)
plt.clf()

Categories