Inset graph, when using a legend placed outside the parent graph - python

I am trying to inset a graph inside the parent graph following the accepted answer here.
However, the plotting framework I am using is quite different:
1) First of all, the Legend is located outside the graph, for which I have followed the second answer posted here, i.e. via shrinking the parent graph:
plt.figure()
# Shrink current axis by 20%
box = ax1.get_position()
ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height])
2) For the labeling, I am using the ax1.legend((p1, p2, p3), ("label for p1", "label for p2", "label for p3")) procedure.
If I ran the code with plt.show() and sys.exit() commented, the entire graph is produced:
However when implementing the inset answer, and trying to inset to the area of the pink and blue data:
(1) Replace plt.figure() by fig, ax1 = plt.subplots(),
(2) Using a ax2 for the inset, since a ax1 has already been used for placing the legend outside the graph,
(3) Uncommentplt.show() and sys.exit(),
no data is plotted both in the parent and inset graphs:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
import sys
x_1 = np.array([ 2.56480648, 2.56635664, 2.57565757, 2.59425943, 2.61906191, 2.64463946,
2.66711671, 2.69966997, 2.72292229, 2.75392539, 2.79422942, 2.81360636,
2.84460946, 2.88026303, 2.91746675, 2.94846985, 2.99187419, 3.01822682,
3.06085609, 3.08565857, 3.12286229, 3.18331833, 3.24067407, 3.25772577,
3.36158616, 3.35616062, 3.43056806, 3.45847085, 3.61574815, 3.65387259,
3.89764927, 9.1 ])
x_2 = np.array([ 5.77982798, 5.77827783, 5.79067907, 5.81083108, 5.82788279, 5.85113511,
5.87438744, 5.89763976, 5.92011701, 5.94414441, 5.96584658, 5.98987399,
6.01467647, 6.03637864, 6.06118112, 6.08443344, 6.11543654, 6.13248825,
6.16194119, 6.18751875, 6.21077108, 6.23479848, 6.26192619, 6.29137914,
6.32083208, 6.35028503, 6.38128813, 6.41306631, 6.45569557, 6.47894789,
6.50530053, 6.55645565, 6.5959846 , 6.62853785, 6.67349235, 6.71612161,
6.76417642, 6.80293029, 6.86726173, 6.91841684, 6.96182118, 7.04165417,
7.10908591, 7.23774877, 7.30208021, 9.40021502])
y_1 = np.array([ 0., 10., 30.1, 50.2, 70.3, 90.4, 110.51, 130.61, 150.71,
170.81, 190.91, 211.01, 231.11, 251.21, 271.31, 291.41, 311.52, 331.62,
351.72, 371.82, 391.92, 412.02, 432.12, 452.22, 472.32, 492.42, 512.53,
532.63, 552.73, 572.83, 592.93, 592.93])
y_2 = np.array([ 0., 10., 30.1, 50.2, 70.3, 90.4, 110.51, 130.61, 150.71,
170.81, 190.91, 211.01, 231.11, 251.21, 271.31, 291.41, 311.52, 331.62,
351.72, 371.82, 391.92, 412.02, 432.12, 452.22, 472.32, 492.42, 512.53,
532.63, 552.73, 572.83, 592.93, 613.03, 633.13, 653.23, 673.33, 693.43,
713.54, 733.64, 753.74, 773.84, 793.94, 814.04, 834.14, 854.24, 874.34,
894.44])
x_3 = np.array([ 273.15, 323.15, 373.15, 423.15, 473.15])
x_4 = np.array([ 295.16725084, 378.53216084, 476.23703528, 490.56204235])
y_3 = np.array([ 1.4709975, 1.42196425, 1.372931 , 1.32389775, 1.2748645 ])
y_4 = np.array([ 1.43766266, 1.46267139, 1.51159861, 1.52367087])
### Plotting:
plt.figure()
#fig, ax1 = plt.subplots()
p1 = plt.scatter(x_1, y_1, color='red', marker='o', s=40)
p3 = plt.scatter(x_2, y_2, marker="o", color='black', facecolors='none', s=40)
p3c = plt.scatter(y_3, x_3, color='magenta', marker="o", facecolors='none', s=40)
p4 = plt.scatter(y_4, x_4, color='blue', marker='o', s=40)
fontP = FontProperties()
fontP.set_size('12')
ax1 = plt.subplot(111)
# Shrink current axis by 20% in order to allow the legend to be outside the plot:
box = ax1.get_position()
ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax1.legend((\
p1,\
p3,\
p3c,\
p4\
),\
(\
"1",\
"2",\
"3",\
"4"\
),\
prop=fontP, loc='center left', bbox_to_anchor=(1, 0.5))# loc=4)
extraticks=[273.15+25]
plt.yticks(list(plt.yticks()[0]) + extraticks)
plt.gca().set_xlim(right=8)
plt.gca().set_ylim(bottom=-41.72, top=1040)
plt.grid()
plt.show()
sys.exit()
left, bottom, width, height = [0.25, 0.6, 0.2, 0.2]
ax2 = fig.add_axes([left, bottom, width, height])
p3 = ax2.scatter(x_2, y_2, color='black', marker="o", facecolors='none', s=40)
p3c = ax2.scatter(x_3, y_3, color='magenta', marker="o", facecolors='none', s=40)
ax2.set_xlim(right=2.26)
plt.gca().set_ylim(bottom=200, top=1040)
plt.grid()
plt.savefig('plot.pdf', bbox_inches='tight')
plt.show()

I think there are simply some useless commands all over the place which make the code produce 2 figures instead of one and several subplots instead of one. Also the limits of the inset seem to be off. Removing all of this would give you the following plot, which might be what you're after.
### Plotting:
fig, ax1 = plt.subplots()
p1 = plt.scatter(x_1, y_1, color='red', marker='o', s=40)
p3 = plt.scatter(x_2, y_2, marker="o", color='black', facecolors='none', s=40)
p3c = plt.scatter(y_3, x_3, color='magenta', marker="o", facecolors='none', s=40)
p4 = plt.scatter(y_4, x_4, color='blue', marker='o', s=40)
fontP = FontProperties()
fontP.set_size('12')
box = ax1.get_position()
ax1.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax1.legend((p1,p3,p3c,p4),("1","2","3","4"),
prop=fontP, loc='center left', bbox_to_anchor=(1, 0.5))
extraticks=[273.15+25]
plt.yticks(list(plt.yticks()[0]) + extraticks)
plt.gca().set_xlim(right=8)
plt.gca().set_ylim(bottom=-41.72, top=1040)
plt.grid()
left, bottom, width, height = [0.25, 0.6, 0.2, 0.2]
ax2 = fig.add_axes([left, bottom, width, height])
p3 = ax2.scatter(x_2, y_2, color='black', marker="o", facecolors='none', s=40)
p3c = ax2.scatter(x_3, y_3, color='magenta', marker="o", facecolors='none', s=40)
plt.grid()
plt.savefig('plot.pdf', bbox_inches='tight')
plt.show()

Related

A polar plot as a subplot within another plot

I just want to plot a subplot inside another plot:
As you can see, in this code I tried to plot this polar plot inside the other plot, but I can't set the size and place of the plot one:
from matplotlib.gridspec import GridSpec
time = np.linspace(0, 10, 1000)
height = np.sin(time)
score = time**2 + height
distribution = np.random.normal(0, 1, len(time))
fig = plt.figure(figsize=(10, 5))
gs = GridSpec(nrows=1, ncols=2)
ax2 = fig.add_subplot(gs[:, 1])
ax2.plot(time, score)
ax3 = fig.add_subplot(111,polar=True)
ax3.set_theta_zero_location("N")
ax3.plot(0-1.5708, 0,'o', linewidth=2,color="k")
theta1 = np.linspace(-0.48332530310852967-1.5708,0.48332530310852967-1.5708, 100)
ax3.fill_between(theta1, -0.1, +0.3, color='r')
theta2 = np.linspace(0.48332530310852967-1.5708,1.449975909325589-1.5708, 100)
ax3.fill_between(theta2, -0.1, +0.3, color='b')
theta3 = np.linspace(1.449975909325589-1.5708,2.4166265155426485-1.5708, 100)
ax3.fill_between(theta3, -0.1, +0.3, color='r')
theta4 = np.linspace(2.4166265155426485-1.5708,3.3832771217597077-1.5708, 100)
ax3.fill_between(theta4, -0.1, +0.3, color='b')
theta5 = np.linspace(3.3832771217597077-1.5708,3.870223983066126-1.5708, 100)
ax3.fill_between(theta5, -0.1, +0.3, color='g')
theta6 = np.linspace(3.870223983066126-1.5708,4.836874589283185-1.5708, 100)
ax3.fill_between(theta6, -0.1, +0.3, color='r')
theta6 = np.linspace(4.836874589283185-1.5708,5.803525195500244-1.5708, 100)
ax3.fill_between(theta6, -0.1, +0.3, color='b')
#ax3.annotate("{}".format(k), xy=[i, j], fontsize=9)
ax3.set_ylim(-10,1)
#ax3.set_xticks(np.linspace(0,2*np.pi,19)[:-1])
#ax3.set_rlabel_position(-47.5) # Move radial labels away from plotted line
ax3.grid(True)
plt.show()
what I have
what I want to have :
from matplotlib.gridspec import GridSpec
from mpl_toolkits.axes_grid.inset_locator import (inset_axes, InsetPosition,
mark_inset)
time = np.linspace(0, 10, 1000)
height = np.sin(time)
score = time**2 + height
distribution = np.random.normal(0, 1, len(time))
fig = plt.figure(figsize=(10, 5))
gs = GridSpec(nrows=1, ncols=2)
ax2 = fig.add_subplot(gs[:, 0])
ax2.plot(time, score)
ax3 = fig.add_axes([0.1, 0.47, 0.25, 0.35], polar=True)
#ax3 = ax2.inset_axes([0.4,0.4,0.2,0.2], subplot_kw={'projection': 'polar'})
ax3.set_theta_zero_location("N")
ax3.plot(0-1.5708, 0,'o', linewidth=2,color="k")
theta1 = np.linspace(-0.48332530310852967-1.5708,0.48332530310852967-1.5708, 100)
ax3.fill_between(theta1, -0.1, +0.3, color='r')
theta2 = np.linspace(0.48332530310852967-1.5708,1.449975909325589-1.5708, 100)
ax3.fill_between(theta2, -0.1, +0.3, color='b')
theta3 = np.linspace(1.449975909325589-1.5708,2.4166265155426485-1.5708, 100)
ax3.fill_between(theta3, -0.1, +0.3, color='r')
theta4 = np.linspace(2.4166265155426485-1.5708,3.3832771217597077-1.5708, 100)
ax3.fill_between(theta4, -0.1, +0.3, color='b')
theta5 = np.linspace(3.3832771217597077-1.5708,3.870223983066126-1.5708, 100)
ax3.fill_between(theta5, -0.1, +0.3, color='g')
theta6 = np.linspace(3.870223983066126-1.5708,4.836874589283185-1.5708, 100)
ax3.fill_between(theta6, -0.1, +0.3, color='r')
theta6 = np.linspace(4.836874589283185-1.5708,5.803525195500244-1.5708, 100)
ax3.fill_between(theta6, -0.1, +0.3, color='b')
#ax3.annotate("{}".format(k), xy=[i, j], fontsize=9)
ax3.set_ylim(-10,1)
#ax3.set_xticks(np.linspace(0,2*np.pi,19)[:-1])
#ax3.set_rlabel_position(-47.5) # Move radial labels away from plotted line
ax3.grid(True)
plt.show()

How to prevent spans from hiding bar charts?

I'm plotting a bar graphic and horizontal spans with this code:
fig = plt.figure('Graphic', figsize=(20,15), dpi=400)
ax1 = fig.add_axes([0.1, 0.1, 0.85, 0.75])
data.plot('DATE',["PP"],kind='bar',color='black', fontsize = 15.0,ax=ax1,alpha=1)
data.plot('DATE',['PP'],kind='line',marker='*',style=['--'],linewidth=1,color='gray', ms=5,ax=ax1)
ax1.axhspan(0, 1, facecolor='lightyellow', alpha=1)
ax1.axhspan(1, 1.5, facecolor='yellow', alpha=1)
ax1.axhspan(1.5, 2, facecolor='lime', alpha=1)
ax1.axhspan(2, 3.5, facecolor='green', alpha=1)
ax1.axhspan(0, -1, facecolor='bisque', alpha=1)
ax1.axhspan(-1, -1.5, facecolor='orange', alpha=1)
ax1.axhspan(-1.5, -2, facecolor='pink', alpha=1)
ax1.axhspan(-2, -3.5, facecolor='red', alpha=1)
The issue is that spans are hiding the Bar graphic. I would like to be able to visualize the spans with the bar graphs. Both with alpha=1. I don't want to reduce the alpha values.
Is this possible?
Thanks in advance.
I am displaying the image with axhspans with alpha=1 covering the bar charts.
I noticed two things that needed to change.
When you use pandas line and bar plots with X-axis being dates, there was/is a bug. Refer to this link. The workaround used here is what was there. Using matplotlib plot instead of pandas helped resolve this.
Refer to zorder. You can specify the order of the various components (line plot, bar, spans) to tell it what will come on top of what. Higher the zorder, the higher the plot will be. I have used 1 for the spans zorder, 2 for the bar plot zorder and 2 for line plot.
Updated code is below. See if this helps.
fig = plt.figure('Graphic', figsize=(20,15), dpi=400)
ax1 = fig.add_axes([0.1, 0.1, 0.85, 0.75])
data.plot('DATE',["PP"],kind='bar',color='black', fontsize = 15.0,ax=ax1,alpha=1, zorder=2) ## Added zorder
# Changed to matplotlib, increased linewidth to 3 so you can see it and zorder=3
ax1.plot(data[['PP']], marker='*',ls='--',linewidth=3,color='gray', ms=5, zorder=3)
## All zorder = 0
ax1.axhspan(0, 1, facecolor='lightyellow', alpha=1, zorder=1)
ax1.axhspan(1, 1.5, facecolor='yellow', alpha=1, zorder=1)
ax1.axhspan(1.5, 2, facecolor='lime', alpha=1, zorder=1)
ax1.axhspan(2, 3.5, facecolor='green', alpha=1, zorder=1)
ax1.axhspan(0, -1, facecolor='bisque', alpha=1, zorder=1)
ax1.axhspan(-1, -1.5, facecolor='orange', alpha=1, zorder=1)
ax1.axhspan(-1.5, -2, facecolor='pink', alpha=1, zorder=1)
ax1.axhspan(-2, -3.5, facecolor='red', alpha=1, zorder=1)
Plot
The order of display in the pandas plot is not adjustable, so I guess we have to deal with it in matplotlib. ax is set up with a line chart and horizontal fill, and a bar chart is added as a second axis. Then I get the order of the line chart, add 1 to the value of the line chart, and set the display order to the bar chart. Since no data was provided, stock price data was used as a sample.
import yfinance as yf
import pandas as pd
data = yf.download("AAPL", start="2022-06-01", end="2022-09-01")
data.index = pd.to_datetime(data.index)
import matplotlib.pyplot as plt
fig = plt.figure('Graphic', figsize=(10,7.5), dpi=100)
ax1 = fig.add_axes([0.1, 0.1, 0.85, 0.75])
ax1.plot(data.index, data['Close'], marker='*', linestyle='--', linewidth=1, color='gray', ms=5)
ax1.axhspan(170, 180, facecolor='lightyellow', alpha=1)
ax1.axhspan(160, 170, facecolor='yellow', alpha=1)
ax1.axhspan(150, 160, facecolor='lime', alpha=1)
ax1.axhspan(145, 150, facecolor='green', alpha=1)
ax1.axhspan(140, 145, facecolor='bisque', alpha=1)
ax1.axhspan(135, 140, facecolor='orange', alpha=1)
ax1.axhspan(130, 135, facecolor='pink', alpha=1)
ax1.axhspan(120, 130, facecolor='red', alpha=1)
ax2 = ax1.twinx()
ax2.bar(x=data.index, height=data['Volume'], color='black')
ax2.set_zorder(ax1.get_zorder()+1)
ax2.set_frame_on(False)
ax1.set_ylim(120, 180)
plt.show()

How to add customized ticks in Heatmap?

I plotted an array in seaborn heatmap, and I want to add tick limits to the axis.
My code:
# plot
eixoz = numpy.linspace(0, Z)
eixor = numpy.linspace(ra, R, nr)
eixox = D
numpy.meshgrid(eixoz, eixor)
ax = seaborn.heatmap(eixox)
ax.invert_yaxis()
plt.xlabel("Eixo z", fontsize=20)
plt.ylabel("Eixo r", fontsize=20)
ax.get_xaxis().set_ticks([])
ax.get_yaxis().set_ticks([])
ax.collections[0].colorbar.set_label("Celsius", fontsize=20)
plt.show()
How can I add those limit ticks in blue? And also, how can I resize the color bar numbers?
The size of the colorbar tick labels can be changed via ax.collections[0].colorbar.ax.tick_params(labelsize=20).
Text at the start and end of the axes can be place using the axes transform, where 0 is the left (or bottom) and 1 is the right (or top) of the axes. Negative values (or values larger than 1) are proportionall outside the axes area. Horizontal and vertical lines can use the same transform, but unlike text need clip_on=False to be drawn outside the axes area.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
len_eixoz = 20
eixox = np.repeat(np.arange(37.55, 37.66, 0.02), len_eixoz).reshape(-1, len_eixoz)
ax = sns.heatmap(eixox)
ax.invert_yaxis()
ax.set_xlabel("Eixo z", fontsize=20)
ax.set_ylabel("Eixo r", fontsize=20)
ax.get_xaxis().set_ticks([])
ax.get_yaxis().set_ticks([])
ax.collections[0].colorbar.set_label("Celsius", fontsize=20)
cbar = ax.collections[0].colorbar.ax.tick_params(labelsize=20)
x0, x1 = 1, 2
y0, y1 = 0, 1
ax.text(0, -0.07, x0, ha='center', va='top', fontsize=20, color='steelblue', transform=ax.transAxes)
ax.text(1, -0.07, x1, ha='center', va='top', fontsize=20, color='steelblue', transform=ax.transAxes)
ax.text(-0.05, 0, y0, ha='right', va='center', fontsize=20, color='steelblue', transform=ax.transAxes)
ax.text(-0.05, 1, y1, ha='right', va='center', fontsize=20, color='steelblue', transform=ax.transAxes)
ax.vlines([0, 1], [0, 0], [-0.06, -0.06], color='crimson', clip_on=False, transform=ax.transAxes)
ax.hlines([0, 1], [0, 0], [-0.04, -0.04], color='crimson', clip_on=False, transform=ax.transAxes)
plt.tight_layout()
plt.show()
Note that calling sns.set(font_scale=1.8) at the start would scale all fonts.

Removing axes and lining up a subplot

I have produced a graph with two subplots and am trying to add a histogram to the end of the residuals plot but am unable to remove the x-axis of the histogram plot and get it to line up with the end of the residual plot.
Here is a copy of my current code:
#graph with histogram and std error plot thing
fig1 = plt.figure(figsize =(9.6,7.2))
ax = fig1.add_axes((0.2,0.4,.75,.6))
ax.errorbar(xval, yval*1000, yerr=yerr*1000, xerr=xerr, marker='x', linestyle='None')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
# Axis labels
plt.xlabel('Height (m)', fontsize = 12)
plt.ylabel('dM/dt (g $s^{-1}$) × $10^{3}$', fontsize = 12)
# Generate best fit line using model function and best fit parameters, and add to plot
fit_line=model_funct(xval, [a_soln, b_soln])
plt.plot(xval, fit_line*1000)
# Set suitable axis limits: you will probably need to change these...
#pyplot.xlim(-1, 61)
#pyplot.ylim(65, 105)
# pyplot.show()
ax2 = fig1.add_axes((0.2,0.2,.75,.2)) #start frame1 at 0.2, 0.4
plt.xlabel("Height of Water (m)", fontsize = 12)
plt.ylabel("Normalised\nResiduals", fontsize = 12) #\n is used to start a new line
ax2.plot(h,normalised_residuals,"x", color = "green")
plt.axhline(0, linewidth=1, linestyle="--", color="black")
plt.savefig("Final Graph with added parts.png", dpi = 500)
ax2.axhspan(ymin = -np.std(normalised_residuals), ymax = np.std(normalised_residuals), color = 'gray', alpha =0.5)
ax3 = fig1.add_axes((1,0.2,0.2,0.2))
ax3.hist(normalised_residuals, bins=8, orientation="horizontal")
ax3.spines['right'].set_visible(False)
ax3.spines['top'].set_visible(False)
ax3.spines['left'].set_visible(False)
ax3.yaxis.set_ticks_position('left')
ax3.xaxis.set_ticks_position('bottom')
and here is a picture of my graph currently:
An example with random data. Using tick_params and manually setting both ylim and the histogram range, did the trick.
import matplotlib.pyplot as plt
import numpy as np
fig1 = plt.figure(figsize=(20, 15))
ax = fig1.add_axes((0.2, 0.4, .75, .6))
ax2 = fig1.add_axes((0.2, 0.2, .75, .2))
ax3 = fig1.add_axes((.95, 0.2, 0.2, 0.2))
xval = (np.linspace(0.02, 0.15, 20)
+ (np.random.default_rng(0).random(20) - 0.5) / 30)
yval = 2 * xval + 0.08
xerr = (np.random.default_rng(0).random(20) * 2 - 1) / 60
yerr = (np.random.default_rng(1).random(20) * 2 - 1) / 60
ax.errorbar(xval, yval, yerr=yerr, xerr=xerr, marker='x', linestyle='None')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.tick_params(labelbottom=False)
ax.set_xlabel('Height (m)', fontsize=12)
ax.set_ylabel('dM/dt (g $s^{-1}$) × $10^{3}$', fontsize=12)
ax2.plot(xval, xerr, 'x', color='green')
ax2.axhline(0, linewidth=1, linestyle='--', color='black')
ax2.axhspan(ymin=-np.std(xerr), ymax=np.std(xerr), color='gray', alpha=0.5)
ax2.set_xlabel('Height of Water (m)', fontsize=12)
ax2.set_ylabel('Normalised\nResiduals', fontsize=12)
resLim = ax2.get_ylim()
ax3.hist(xerr, bins=8, orientation='horizontal', range=resLim, rwidth=0.9)
ax3.spines['right'].set_visible(False)
ax3.spines['top'].set_visible(False)
ax3.spines['left'].set_visible(False)
ax3.spines['bottom'].set_visible(False)
ax3.tick_params(labelbottom=False, labelleft=False, bottom=False, left=False)
ax3.set_ylim(resLim)
fig1.savefig('so.png', bbox_inches='tight')

matplotlib: horizontal spacing of subplots with equal aspect ratio

I'm trying to draw two rows with three columns of pcolormesh plots and a combined colorbar for all plots. So far it seems to work. However, I'm sure I'm not using the most elegant way...
The only problem I have, is that I can't decrease the horizontal spacing any further. The following line should set the horizontal spacing to zero:
fig.subplots_adjust(left=0.05, right=0.98, top=0.93, bottom=0.00, wspace=0, hspace=0.03)
But this does not work in conjunction with
ax.set_aspect('equal')
I've attached a small code snippet that creates the following figure:
Example figure
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
rows = 2
columns = 3
fig = plt.figure()
gs = gridspec.GridSpec(rows+1, columns)
lines = []
x = np.linspace(1,10,100)
y = x
X, Y = np.meshgrid(x,y)
Z = np.random.rand(100,100)
lines = []
for i in range(rows):
lines.append([])
for j in range(columns):
ax = fig.add_subplot(gs[i, j])
line = ax.pcolormesh(X, Y, Z, cmap=plt.cm.Reds)
lines[i].append(line)
ax.set_aspect('equal')
for tick in ax.get_xticklabels():
tick.set_rotation(45)
if i!=rows-1:
ax.set_xticklabels([])
if j!=0:
ax.set_yticklabels([])
#title
props = dict(boxstyle='round', facecolor='white', alpha=0.7)
ax.text(0.05, 0.95, "plot (%i, %i)" % (i,j), transform=ax.transAxes, fontsize=5,
verticalalignment='top', bbox=props)
ax.tick_params(labelsize=7)
cb_ax = fig.add_subplot(gs[-1,:])
cb_ax.set_aspect(0.05)
cbar = fig.colorbar(lines[0][0], cax=cb_ax, orientation='horizontal')
cb_ax.tick_params(labelsize=7)
fig.subplots_adjust(left=0.05, right=0.98, top=0.93, bottom=0.00, wspace=0, hspace=0.03)
#fig.tight_layout()
fig.text(0.5, 0.2, "x axis", ha='center', va='center')
fig.text(0.5, 0.97, "overall title", ha='center', va='center')
fig.text(0.02, 0.5, "y axis", ha='center', va='center', rotation='vertical')
fig.text(0.5, 0.02, "quantity [unit]", ha='center', va='center',)
plt.savefig("test.png", dpi=600)

Categories

Resources