Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Barplots
#1
I'm trying to create horizontal and vertical bar plots. Below is my code. However, pressing "return" after the first plot command (line 3 of the code), all I get is the first output listed below. And after pressing "return" after the second plot command (line 4 of the code), I get the second output listed below. I do not get a graphical bar plot. I have imported everything I can think of: numpy, matplotlib.pyplot, pandas (i.e. things that I need to plot the graph as well as things I don't need) but horizonal and vertical bar plots are NOT being produced. Could someone help? I'm a complete newbie.


fig, axes = plt.subplots(2,1)
data = pd.Series(np.random.rand(16), index=list('abcdefghijklmnop'))
data.plot.bar(ax=axes[0], color='k', alpha=0.7)
data.plot.barh(ax=axes[1], color='k', alpha=0.7)
Output received:
<matplotlib.axes._subplots.AxesSubplot at 0x2016a51ad30>
<matplotlib.axes._subplots.AxesSubplot at 0x2016a54e438>
Reply
#2
Call plt.show() and it seems to give what you want:
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt


ig, axes = plt.subplots(2,1)
data = pd.Series(np.random.rand(16), index=list('abcdefghijklmnop'))
data.plot.bar(ax=axes[0], color='k', alpha=0.7)
data.plot.barh(ax=axes[1], color='k', alpha=0.7)

plt.show()
   
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020