Python+matplotlib+numpy實現(xiàn)在不同平面的二維條形圖
更新時間:2018年01月02日 14:15:25 投稿:mengwei
這篇文章主要介紹了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中dtypes和type()函數(shù)的區(qū)別示例詳解
type()是python內(nèi)置的函數(shù),type()返回數(shù)據(jù)結(jié)構(gòu)類型(list、dict、numpy.ndarray 等),dtype返回數(shù)據(jù)元素的數(shù)據(jù)類型(int、float等),這篇文章主要給大家介紹了關(guān)于python中dtypes和type()函數(shù)區(qū)別的相關(guān)資料,需要的朋友可以參考下2024-03-03python正則表達式函數(shù)match()和search()的區(qū)別
match()和search()都是python中的正則匹配函數(shù),那這兩個函數(shù)有何區(qū)別呢?本文詳細介紹了這2個函數(shù)的區(qū)別2021-10-10