matplotlib 将图周围的线加粗matplotib [duplicate]

bzzcjhmw  于 2023-02-05  发布在  其他
关注(0)|答案(3)|浏览(284)
    • 此问题在此处已有答案**:

How to change Border width in MatPlotLib?(1个答案)
How to add border or frame around individual subplots(2个答案)
matplotlib border width(3个答案)
How to add black border to matplotlib 2.0 ax object In Python 3?(3个答案)
3天前关闭。
我怎样才能做出一个像这样用粗线包围的图呢?

wz3gfoph

wz3gfoph1#

我将使用 matplotlibspines中的set_linewidthset_color参数:
轴线--表示数据区边界的线。

import matplotlib.pyplot as plt

C, W, L, T = "black", 4, 2, 7 # <- adjust here
#Color, Width, Length, Tickness --------------

fig, ax = plt.subplots(figsize=(W, L))
list_of_spines = ["left", "right", "top", "bottom"]

for sp in list_of_spines:
    ax.spines[sp].set_linewidth(T)
    ax.spines[sp].set_color(C)

ax.set_xticks([])
ax.set_yticks([])

plt.show();

输出:

5m1hhzi4

5m1hhzi42#

在类似的问题上,您可以使用answer的以下代码

import matplotlib.pyplot as plt
import matplotlib as mpl
plt.rcParams["axes.edgecolor"] = "black"
plt.rcParams["axes.linewidth"] = 2.50
fig = plt.figure(figsize = (4.1, 2.2))
ax = fig.add_subplot(111)
u3r8eeie

u3r8eeie3#

您可以设置图像周围边框的宽度和颜色,如下所示:

from matplotlib import pyplot as plt

# some data for demonstration purposes
import numpy as np
x = np.random.randn(100)

# create figure
fig, ax = plt.subplots()

ax.plot(x)

# set the border width
fig.set_linewidth(10)

# set the border colour (to black in this case)
fig.set_edgecolor("k")

# show the figure
fig.show()

这给出:

相关问题