久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 python 2.7 中更改 matplotlib.bar 順序

Change matplotlib.bar Order in python 2.7(在 python 2.7 中更改 matplotlib.bar 順序)
本文介紹了在 python 2.7 中更改 matplotlib.bar 順序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在這個例子中:

import matplotlib.pyplot as plt顏色= ['白色','橙色','綠色','紫色']費率 = ['5','5','4','3']plt.bar(顏色,費率)

圖中的條形按字母順序排列.

如何使它們以與代碼中相同的順序顯示(從最高到最低的比率)?

解決方案

Matplotlib 2.1 為

In this example:

import matplotlib.pyplot as plt

colors = ['white', 'orange', 'green', 'purple']
rates = ['5','5','4','3']

plt.bar(colors, rates)

the bars in the plot are ordered by the alphabetic order.

How do I make them to show in the same order as they are in the code (from highest to lowest rate)?

解決方案

Matplotlib 2.1 provides the new option to use strings as input to its plotting functions - called "categoricals". This is a new feature and not yet completely working. One caveat is that strings are automatically sorted (alphabetically). This restriction will be removed in the next release.

Until then you would produce your plot just as in times when matplotlib did not even allow for strings to put in. Convert data to numbers, and plot against the list index. Afterwards set the ticklabels to their names.

import matplotlib.pyplot as plt

colors = ['white', 'orange', 'green', 'purple']
rates = ['5','5','4','3']

plt.bar(range(len(colors)), list(map(float,rates)) )
plt.xticks(range(len(colors)), colors)

plt.show()

這篇關于在 python 2.7 中更改 matplotlib.bar 順序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 国产成人影院 | 日本一区二区三区在线观看 | 中文字幕一区二区三区乱码在线 | 日韩精品成人一区二区三区视频 | 日韩欧美一区二区三区免费观看 | 黄色一级电影免费观看 | 91资源在线 | 日本一区二区电影 | 狠狠干网| 盗摄精品av一区二区三区 | 亚洲欧美自拍偷拍视频 | 亚洲福利在线观看 | 精品国产91乱码一区二区三区 | 青青久久久 | 91国产视频在线观看 | 欧美中国少妇xxx性高请视频 | 伊人最新网址 | 日韩av一区二区在线观看 | 久久综合爱 | 国产高清一二三区 | 久久久夜色精品亚洲 | 日韩综合网 | 激情一区二区三区 | 在线久草| 欧美色欧美亚洲另类七区 | 国产成人免费网站 | 超碰97av| 九九热在线观看 | 在线91 | 一区二区三区在线播放视频 | 国产精品久久在线 | a毛片视频网站 | 久久久久久精 | 欧美aaaaaaaaaa | 国产一区二区三区四区三区四 | 最新av在线播放 | 97精品超碰一区二区三区 | www.99热 | 综合久久av| 男人的天堂一级片 | 欧美国产日韩在线观看成人 |