简体   繁体   中英

matplotlib how to change figure size but NOT plot size

For this simple plot I want to enlarge the figure size but I want to keep the actual plot size. How is this possible? Until now I found just a lot of possibilities which changed both sizes together.

import matplotlib.pyplot as plt

plt.plot([-1, -4.5, 16, 23, 15, 59])
plt.show()

You can achieve a constant axes sizes by addind the axes manually. In my code example I introduce an scale factor sc which determines the ratio of figure and axes size.

import matplotlib.pyplot as plt

gr = (1 + np.sqrt(5))/2
sc = 2

fig_w = 3 * gr * sc
fig_h = 3 * sc

fig =  plt.figure(figsize=(fig_w, fig_h))

panel_width = 1/sc
panel_height = 1/sc
off = (1 - 1/sc) / 2

ax = fig.add_axes([off, off, panel_width, panel_height])
ax.plot([-1, -4.5, 16, 23, 15, 59])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM