程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python drawing

編輯:Python

Signature:
plt.bar(
    x,
    height,
    width=0.8,
    bottom=None,
    *,
    align='center',
    data=None,
    **kwargs,
)
Docstring:
Make a bar plot.

The bars are positioned at *x* with the given *align*\ment. Their
dimensions are given by *height* and *width*. The vertical baseline
is *bottom* (default 0).

Parameters
----------
x : float or array-like
    The x coordinates of the bars. See also *align* for the
    alignment of the bars to the coordinates.

height : float or array-like
    The height(s) of the bars.

width : float or array-like, default: 0.8
    The width(s) of the bars.

bottom : float or array-like, default: 0
    The y coordinate(s) of the bars bases.

align : {'center', 'edge'}, default: 'center'
    Alignment of the bars to the *x* coordinates:

    - 'center': Center the base on the *x* positions.
    - 'edge': Align the left edges of the bars with the *x* positions.

    To align the bars on the right edge pass a negative *width* and
    ``align='edge'``.

Parallel bar chart

import matplotlib.pyplot as plt
import numpy as np


# Enter Statistics
waters = ('cc', 'green', 'water', 'juce', 'other')
buy_number_male = [6, 7, 6, 1, 2]
buy_number_female = [9, 4, 4, 5, 6]

bar_width = 0.3  # Strip width
index_male = np.arange(len(waters))  # Abscissa of the bar chart for boys
index_female = index_male + bar_width  # Abscissa of the bar chart for girls

# Use twice bar Function to draw two sets of bar graphs
plt.bar(index_male, height=buy_number_male, width=bar_width, color='b', label='female')
plt.bar(index_female, height=buy_number_female, width=bar_width, color='g', label='male')


plt.xticks(index_male + bar_width/2, waters)  # Let the abscissa axis scale display waters Drinking water in , index_male + bar_width/2 The position of the scale for the abscissa
plt.ylabel('size')  # Ordinate axis title
plt.title('static result')  # Graphic title
plt.legend()  # Show Legend

plt.show()

  Bar chart

import matplotlib.pyplot as plt
waters = ('cc', 'green', 'water', 'juice', 'other')
buy_number = [6, 7, 6, 1, 2]

plt.barh(waters, buy_number)  # Horizontal bar graph function barh
plt.title('female juice static result')

plt.show()

  stacked column chart

import numpy as np
import matplotlib.pyplot as plt
size = 5
x = np.arange(size)
a = np.random.random(size)
b = np.random.random(size)
plt.bar(x, a, label='a')
plt.bar(x, b, bottom=a, label='b')
plt.legend()
plt.show()



matplotlib mapping —— Histogram - You know  
python Draw a bar chart ( Histogram )_ Attitude and work habits determine the height of life blog -CSDN Blog _python Bar chart


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved