Python+matplotlib+numpy實現(xiàn)在不同平面的二維條形圖
在不同平面上繪制二維條形圖。
本實例制作了一個3d圖,其中有二維條形圖投射到平面y=0,y=1,等。
演示結(jié)果:


完整代碼:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
# Fixing random state for reproducibility
np.random.seed(19680801)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
colors = ['r', 'g', 'b', 'y']
yticks = [3, 2, 1, 0]
for c, k in zip(colors, yticks):
# Generate the random data for the y=k 'layer'.
xs = np.arange(20)
ys = np.random.rand(20)
# You can provide either a single color or an array with the same length as
# xs and ys. To demonstrate this, we color the first bar of each set cyan.
cs = [c] * len(xs)
cs[0] = 'c'
# Plot the bar graph given by xs and ys on the plane y=k with 80% opacity.
ax.bar(xs, ys, zs=k, zdir='y', color=cs, alpha=0.8)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
# On the y axis let's only label the discrete values that we have data for.
ax.set_yticks(yticks)
plt.show()
腳本運行時間:(0分0.063秒)
總結(jié)
以上就是本文關(guān)于Python+matplotlib+numpy實現(xiàn)在不同平面的二維條形圖的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!
相關(guān)文章
使用python怎樣產(chǎn)生10個不同的隨機數(shù)
這篇文章主要介紹了使用python實現(xiàn)產(chǎn)生10個不同的隨機數(shù)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07
Django框架獲取form表單數(shù)據(jù)方式總結(jié)
這篇文章主要介紹了Django框架獲取form表單數(shù)據(jù)方式總結(jié),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-04-04
詳解pyqt中解決國際化tr()函數(shù)不起作用的問題
本文主要介紹了pyqt中解決國際化tr()函數(shù)不起作用的問題,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-02-02
python實現(xiàn)每天自動簽到領(lǐng)積分的示例代碼
這篇文章主要介紹了python實現(xiàn)每天自動簽到領(lǐng)積分的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
Windows系統(tǒng)下實現(xiàn)pycharm運行.sh文件(本地運行和打開服務(wù)器終端)
PyCharm是Python開發(fā)的高效率IDE,但是很多時候需要同時開發(fā)Bash(shell)腳本,下面這篇文章主要給大家介紹了關(guān)于Windows系統(tǒng)下實現(xiàn)pycharm運行.sh文件(本地運行和打開服務(wù)器終端)的相關(guān)資料,需要的朋友可以參考下2022-09-09
對python3 Serial 串口助手的接收讀取數(shù)據(jù)方法詳解
今天小編就為大家分享一篇對python3 Serial 串口助手的接收讀取數(shù)據(jù)方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-06-06

