xxxxxxxxxx
import matplotlib.pyplot as plt
import numpy as np
plt.bar(np.arange(0,100),np.arange(0,100))
xxxxxxxxxx
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
langs = ['C', 'C++', 'Java', 'Python', 'PHP']
students = [23,17,35,29,12]
ax.bar(langs,students)
plt.show()
xxxxxxxxxx
import matplotlib.pyplot as plt
data = [5., 25., 50., 20.]
plt.bar(range(len(data)),data)
plt.show()
// to set the thickness of a bar, we can set 'width'
// plt.bar(range(len(data)), data, width = 1.)
xxxxxxxxxx
import matplotlib.pyplot as plt
# Data for the bar chart
x = ['Category 1', 'Category 2', 'Category 3']
y = [10, 15, 7]
# Creating a bar chart
plt.bar(x, y)
# Adding labels and title
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Bar Chart')
# Displaying the bar chart
plt.show()
xxxxxxxxxx
# For whole dataframe
df.plot(kind="bar")
# Bar plot
df["col"].plot(kind = "bar")
# Horizontal bar plot
df["col"].plot(kind = "barh")
xxxxxxxxxx
import matplotlib.pyplot as plt
# Sample data
x = ['A', 'B', 'C', 'D', 'E']
y = [10, 5, 12, 8, 9]
# Create bar plot
plt.bar(x, y)
# Customize labels and title
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Bar Plot Example')
# Display the plot
plt.show()
xxxxxxxxxx
import numpy as np
import matplotlib.pyplot as plt
data = [[30, 25, 50, 20],
[40, 23, 51, 17],
[35, 22, 45, 19]]
X = np.arange(4)
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.bar(X + 0.00, data[0], color = 'b', width = 0.25)
ax.bar(X + 0.25, data[1], color = 'g', width = 0.25)
ax.bar(X + 0.50, data[2], color = 'r', width = 0.25)
xxxxxxxxxx
import matplotlib.pyplot as plt
fig, ax = plt.subplots
# Create Bar plot
ax.bar(df.index, df["col1"], label="col1")
# Create stacked bar plot keeping the previous barplot below
ax.bar(df.index, df["col2"], bottom=df["col1"], label="col2")
# Create stacked bar plot keeping the previous barplot below
ax.bar(df.index, df["col3"], bottom=df["col1"] + df["col2"], label="col3")
# Rotate tick x axis labels to 90 degree
ax.set_xticklabels(df.index, rotation=90)
ax.set_ylabel("Y axis label")
# Show legend
ax.legend()
plt.show()
xxxxxxxxxx
import numpy as npimport matplotlib.pyplot as plt# data to plotn_groups = 4means_frank = (90, 55, 40, 65)means_guido = (85, 62, 54, 20)# create plotfig, ax = plt.subplots()index = np.arange(n_groups)bar_width = 0.35opacity = 0.8rects1 = plt.bar(index, means_frank, bar_width,alpha=opacity,color='b',label='Frank')rects2 = plt.bar(index + bar_width, means_guido, bar_width,alpha=opacity,color='g',label='Guido')plt.xlabel('Person')plt.ylabel('Scores')plt.title('Scores by person')plt.xticks(index + bar_width, ('A', 'B', 'C', 'D'))plt.legend()plt.tight_layout()plt.show()
xxxxxxxxxx
import matplotlib.pyplot as plt; plt.rcdefaults()import numpy as npimport matplotlib.pyplot as pltobjects = ('Python', 'C++', 'Java', 'Perl', 'Scala', 'Lisp')y_pos = np.arange(len(objects))performance = [10,8,6,4,2,1]plt.bar(y_pos, performance, align='center', alpha=0.5)plt.xticks(y_pos, objects)plt.ylabel('Usage')plt.title('Programming language usage')plt.show()