Good morning,
I'm looking for examples of creating a bar chart and then adding
a line chart on top of it (with the same y-axis). I haven't had
much luck with Google (probably using the wrong search terms).
Thanks!
Jeff
Good morning,
I'm looking for examples of creating a bar chart and then adding
a line chart on top of it (with the same y-axis). I haven't had
much luck with Google (probably using the wrong search terms).
Thanks!
Jeff
Jeff,
You should be able to just call the bar() function and then call the plot() function using the same axes object. For example (untested):
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca()
xs = np.arange(10)
ys = np.random.rand(10)
ax.bar(xs, ys)
ax.plot(xs, ys)
plt.show()
I hope that helps!
Ben Root
On Wed, Feb 23, 2011 at 8:34 AM, Jeff Layton <laytonjb@…872…> wrote:
Good morning,
I’m looking for examples of creating a bar chart and then adding
a line chart on top of it (with the same y-axis). I haven’t had
much luck with Google (probably using the wrong search terms).
Thanks!
Jeff
That worked perfectly! I guess I was looking for something
more complicated and it was that simple.
Thanks!
Jeff
On 02/23/2011 09:50 AM, Benjamin Root wrote:
On Wed, Feb 23, 2011 at 8:34 AM, Jeff > Layton <laytonjb@...872...> > wrote:
Good morning,
I'm looking for examples of creating a bar chart and then
adding
a line chart on top of it (with the same y-axis). I haven't
had
much luck with Google (probably using the wrong search terms). Thanks! Jeff
Jeff, You should be able to just call the bar() function and then
call the plot() function using the same axes object. For
example (untested):import numpy as np import matplotlib.pyplot as plt fig = plt.figure() ax = fig.gca() xs = np.arange(10) ys = np.random.rand(10) ax.bar(xs, ys) ax.plot(xs, ys) plt.show() I hope that helps! Ben Root