When I need to plot 2 series on y axis, I don’t know if this is the best way. It works with lines, but it does not work with line + bars. If I set y2
kind='bar'
, this serie disappears. indexesM
is my dataframe. This is the code:
JavaScript
x
10
10
1
x = indexesM.index.to_timestamp()
2
y0 = indexesM['cdi t12m']
3
y1 = indexesM['ipca t12m']
4
y2 = indexesM['br real yield t12m']
5
fig, ax = plt.subplots()
6
ax.plot(x, y0, label='CDI')
7
ax.plot(x, y1, label='IPCA')
8
ax.plot(x, y2, label='Juro real')
9
plt.show()
10
Advertisement
Answer
I created a composite graph by customizing a sample from the official reference. It uses ax.bar()
.
JavaScript
1
15
15
1
import matplotlib.pyplot as plt
2
3
data = {'apple': 10, 'orange': 15, 'lemon': 5, 'lime': 20}
4
names = list(data.keys())
5
values = list(data.values())
6
7
fig, ax = plt.subplots(figsize=(9, 3))
8
ax.bar(names, values, color='g')
9
ax.scatter(names, values, color='r', s=30)
10
ax.plot(names, values, color='b', lw=2)
11
12
ax.set_title('Categorical Plotting')
13
14
plt.show()
15