Python(数据可视化)
Python (data visualization)
如何使 matplotlib 图(图 2)与 seaborn(图 1)相同?我想删除中央网格。
我尝试使用 plt.gca().axes.xaxis.set_ticklabels([])
,但它也删除了标签。
如果图中已经存在网格,如图 2 所示,您可以关闭通过 b = False
和 axis = 'x'
到 plt.grid()
的水平网格线:
ax.grid(b = False, axis = 'x')
示例:
import matplotlib.pyplot as plt
x = ['a', 'b', 'c', 'd', 'e']
y = [10, 15, 11, 12, 8]
plt.style.use('seaborn-whitegrid')
fig, ax = plt.subplots()
ax.bar(x = x, height = y, color = 'blue')
ax.grid(b = False, axis = 'x')
plt.show()
如何使 matplotlib 图(图 2)与 seaborn(图 1)相同?我想删除中央网格。
我尝试使用 plt.gca().axes.xaxis.set_ticklabels([])
,但它也删除了标签。
如果图中已经存在网格,如图 2 所示,您可以关闭通过 b = False
和 axis = 'x'
到 plt.grid()
的水平网格线:
ax.grid(b = False, axis = 'x')
示例:
import matplotlib.pyplot as plt
x = ['a', 'b', 'c', 'd', 'e']
y = [10, 15, 11, 12, 8]
plt.style.use('seaborn-whitegrid')
fig, ax = plt.subplots()
ax.bar(x = x, height = y, color = 'blue')
ax.grid(b = False, axis = 'x')
plt.show()