0

I have two figs fig1.png and fig2.png made of matplotlib in python code, now in some papers, I want to merge these two figs together, and give them (a) and (b) text labels in the top left area, respectively. How can I use matplotlib do it? I have the codes to generate fig1.png and fig2.png with fig1.py,fig2.py, is there any other convenient way ?like write another short code to do it?

Yin Ge
  • 35
  • 4

1 Answers1

0

How easily you can combine two figures depends on how complex they are. If they are both simple figures with single axes it is relatively straightforward.

Since you have the code to generate the two axes, I would start by putting that code into a single file and then modifying your code to plot to subplot axes.

You can layout multiple axes within a figure as follows:

from matplotlib.pyplot import plt
fig, ax = plt.subplots(1,2) #nrows, ncols

The variable ax is now a list of two axes onto which you can plot.

Subplot Frames

So for example, to plot to the left hand side you can use:

ax[0].plot([1,2,3,4,5]

To the right:

ax[1].plot([1,2,3,4,5]

You can also set labels on the subplots using .set_title(). A complete example:

ax[0].plot([1,2,3,4,5])
ax[0].set_title("A")
ax[1].plot([5,4,3,2,1])
ax[1].set_title("B")

Completed plot

mfitzp
  • 15,275
  • 7
  • 50
  • 70
  • however, what I've asked is more complex. the Label should add to the left bottom side of axis, like most scientific papers. I've tried another way to do it, using the Image function to merge them. – Yin Ge May 22 '16 at 04:00