當前位置: 首頁>>代碼示例>>Python>>正文


Python Die.x_labels方法代碼示例

本文整理匯總了Python中die.Die.x_labels方法的典型用法代碼示例。如果您正苦於以下問題:Python Die.x_labels方法的具體用法?Python Die.x_labels怎麽用?Python Die.x_labels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在die.Die的用法示例。


在下文中一共展示了Die.x_labels方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Die

# 需要導入模塊: from die import Die [as 別名]
# 或者: from die.Die import x_labels [as 別名]
die_2 = Die(10)

# Make some rolls, and store results in a list.
results = []

for roll_num in range(50000):
    result = die_1.roll() + die_2.roll()
    results.append(result)

# Analyze the results.
frequencies = []

max_result = die_1.num_sides + die_2.num_sides

for value in range(2, max_result + 1):
    frequency = results.count(value)
    frequencies.append(frequency)

# print(frequencies)

# Visualize the results.
hist = pygal.Bar()

hist.title = "Results of rolling a D6 and a D10 50,000 times."
hist.x_labels = Die.x_labels(2, max_result)
hist.x_title = "Result"
hist.y_title = "Frequency of Result"

hist.add('D6 + D10', frequencies)
hist.render_to_file('different_dice_visual.svg')
開發者ID:crystalDf,項目名稱:Python-Crash-Course-Chapter-15-Data-Visualization,代碼行數:32,代碼來源:different_dice_visual.py

示例2: Die

# 需要導入模塊: from die import Die [as 別名]
# 或者: from die.Die import x_labels [as 別名]
from die import Die

# Create a D6
die = Die()

# Make some rolls, and store results in a list.
results = []

for roll_num in range(1000):
    result = die.roll()
    results.append(result)

# Analyze the results.
frequencies = []
for value in range(1, die.num_sides + 1):
    frequency = results.count(value)
    frequencies.append(frequency)

# print(frequencies)

# Visualize the results.
hist = pygal.Bar()

hist.title = "Results of rolling one D6 1000 times."
hist.x_labels = Die.x_labels(1, 6)
hist.x_title = "Result"
hist.y_title = "Frequency of Result"

hist.add('D6', frequencies)
hist.render_to_file('die_visual.svg')
開發者ID:crystalDf,項目名稱:Python-Crash-Course-Chapter-15-Data-Visualization,代碼行數:32,代碼來源:die_visual.py


注:本文中的die.Die.x_labels方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。