Python+matplotlib+numpy實(shí)現(xiàn)在不同平面的二維條形圖
在不同平面上繪制二維條形圖。
本實(shí)例制作了一個(gè)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()
腳本運(yùn)行時(shí)間:(0分0.063秒)
總結(jié)
以上就是本文關(guān)于Python+matplotlib+numpy實(shí)現(xiàn)在不同平面的二維條形圖的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!
相關(guān)文章
詳解Python中math和decimal模塊的解析與實(shí)踐
在Python中,math?和?decimal?模塊是處理數(shù)學(xué)運(yùn)算的重要工具,本文將深入探討這兩個(gè)模塊的基礎(chǔ)知識(shí),并通過(guò)實(shí)際的代碼示例演示它們的用法,希望對(duì)大家有所幫助2024-02-02詳解Django之a(chǎn)uth模塊(用戶認(rèn)證)
這篇文章主要介紹了詳解Django之a(chǎn)uth模塊(用戶認(rèn)證),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-04-04Python使用enumerate獲取迭代元素下標(biāo)
這篇文章主要介紹了python使用enumerate獲取迭代元素下標(biāo),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02python實(shí)現(xiàn)人像動(dòng)漫化的示例代碼
這篇文章主要介紹了python實(shí)現(xiàn)人像動(dòng)漫化的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05python中dtypes和type()函數(shù)的區(qū)別示例詳解
type()是python內(nèi)置的函數(shù),type()返回?cái)?shù)據(jù)結(jié)構(gòu)類型(list、dict、numpy.ndarray 等),dtype返回?cái)?shù)據(jù)元素的數(shù)據(jù)類型(int、float等),這篇文章主要給大家介紹了關(guān)于python中dtypes和type()函數(shù)區(qū)別的相關(guān)資料,需要的朋友可以參考下2024-03-03python正則表達(dá)式函數(shù)match()和search()的區(qū)別
match()和search()都是python中的正則匹配函數(shù),那這兩個(gè)函數(shù)有何區(qū)別呢?本文詳細(xì)介紹了這2個(gè)函數(shù)的區(qū)別2021-10-10