import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
条形图
np.random.seed(0)
x = np.arange(5)
y = np.random.randint(-5,5,5)
fig,axes = plt.subplots(ncols=2)
v_bars = axes[0].bar(x,y,color='r')
h_bars = axes[1].barh(x,y,color='r')
fig,axes = plt.subplots(ncols=2)
v_bars = axes[0].bar(x,y,color='r')
h_bars = axes[1].barh(x,y,color='r')
axes[0].axhline(0,color='black',linewidth=2)
axes[1].axvline(0,color='black',linewidth=2)
<matplotlib.lines.Line2D at 0x221cfb39908>
复杂一点的条形图
fig,ax = plt.subplots()
v_bars = ax.bar(x,y,color='b')
for bar, height in zip(v_bars, y):
if height < 0:
bar.set(edgecolor='red', color='red')