matplotlib - bar chart

matplotlib - bar chart

This example showcases a simple bar chart.

  • 1 example

这里写图片描述

"""
====================
bar chart
====================

This example showcases a simple bar chart.
"""

import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)

plt.rcdefaults()

fig, ax = plt.subplots()

# Example data
people = ('James', 'Durant', 'Kobe', 'Wade', 'Curry', 'Magic', 'Hardan')

x_pos = np.arange(len(people))
performance = 5 + 10 * np.random.rand(len(people))

error = np.random.rand(len(people)) / 4
plt.bar(x_pos, performance, xerr=error, align='center', alpha=0.9, color='green', ecolor='black')

plt.xticks(x_pos, people)
plt.ylabel('Performance')
plt.title('How efficient do you want to go today?')
plt.savefig("bar.png", format="png")

plt.show()
  • 2 example

这里写图片描述

"""
====================
bar chart
====================

This example showcases a simple bar chart.
"""

import matplotlib.pyplot as plt
import numpy as np

# Fixing random state for reproducibility
np.random.seed(19680801)

plt.rcdefaults()

fig, ax = plt.subplots()

# Example data
people = ('James', 'Durant', 'Kobe', 'Wade', 'Curry', 'Magic', 'Hardan')

x_pos = np.arange(len(people))
performance = 5 + 10 * np.random.rand(len(people))

# error = np.random.rand(len(people)) / 4
# plt.bar(x_pos, performance, xerr=error, align='center', alpha=0.9, color='green', ecolor='black')

plt.bar(x_pos, performance, align='center', alpha=0.9, color='green', ecolor='black')

plt.xticks(x_pos, people)
plt.ylabel('Performance')
plt.title('How efficient do you want to go today?')
plt.savefig("bar.png", format="png")

plt.show()

猜你喜欢

转载自blog.csdn.net/chengyq116/article/details/81259244
bar