最近我一直在使用matplotlib
样式表。我真的很喜欢seaborn-white
看起来很干净,我希望能够将边框添加到其他样式,如ggplot
或seaborn-whitegrid
。如何将黑色边框添加到matplotlib 2.0`ax`对象在Python 3中?
如何在我的ax
对象周围添加黑色边框fig, ax = plt.subplots()
?
import pandas as pd
import numpy as np
from collections import *
Se_data = pd.Series(Counter(np.random.randint(0,10,100)))
with plt.style.context("seaborn-whitegrid"):
fig, ax = plt.subplots()
Se_data.plot(kind="barh", ax=ax, title="No Border")
with plt.style.context("seaborn-white"):
fig, ax = plt.subplots()
Se_data.plot(kind="barh", ax=ax, title="With Border")
针对下面的答案:
Se_data = pd.Series(Counter(np.random.randint(0,10,100)))
with plt.style.context("seaborn-whitegrid"):
fig, ax = plt.subplots()
Se_data.plot(kind="barh", ax=ax, title="No Border")
ax.spines['bottom'].set_color('0.5')
ax.spines['top'].set_color(None)
ax.spines['right'].set_color('0.5')
ax.spines['left'].set_color(None)
ax.patch.set_facecolor('0.1')
plt.grid(b=True, which='major', color='0.2', linestyle='-')
plt.grid(b=True, which='minor', color='0.2', linestyle='-')
ax.tick_params(axis='x', colors='0.7', which='both')
ax.tick_params(axis='y', colors='0.7', which='both')
ax.yaxis.label.set_color('0.9')
ax.xaxis.label.set_color('0.9')
ax.margins(5)
fig.patch.set_facecolor('0.15')
我觉得我失去了一些东西。如果你喜欢“seaborn-white”风格,那么使用它代替任何其他风格有什么问题? – ImportanceOfBeingErnest
我想知道边界是如何分配的,所以我可以将它添加到任何阴谋 –
我想我的答案下面的答案。边界总是在那里,只是它们的颜色更暗,而且“seaborn-white”风格的线条更粗。 – ImportanceOfBeingErnest