简体   繁体   中英

How to change the bounding box linewidth of a plot in python?

I am getting trouble in finding example of changing linewidth of the boundary box of a plot in Pyhton plot.

For example, fig=plt.figure(figsize=(4.5, 4)) this command gives the dimension of the box in which python will plot the graph. But how to increase the linewidth of this boundary?

There are few options to do this depending on which boundary you are talking about.

Window. fig=plt.figure(figsize=(4.5, 4)) command embeds figure in window which is controlled by system. It's quite hard to find any solution here unless it's a hack. The only accessible option is to use root.overrideredirect(True) here:

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(4.5, 4))
ax = fig.gca()
mng = plt.get_current_fig_manager()
mng.window.overrideredirect(True)
plt.show()

Figure. Another option is to change border of matplotlib.pyplot.figure :

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(4.5, 4), edgecolor='blue', linewidth=3)
ax = fig.gca()
plt.show()

Axis.

If the option is to change width of matplotlib.pyplot.axis :

import matplotlib.pyplot as plt
fig = plt.figure(figsize=(4.5, 4))
ax = fig.gca()
for axis in ['top','bottom','left','right']:
    ax.spines[axis].set_linewidth(0.5)
plt.show()

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