最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python繪制發(fā)散型柱狀圖+誤差陰影時(shí)間序列圖+雙坐標(biāo)系時(shí)間序列圖+繪制金字塔圖

 更新時(shí)間:2022年08月16日 16:32:49   作者:不再依然07  
這篇文章主要介紹了python繪制發(fā)散型柱狀圖+誤差陰影時(shí)間序列圖+雙坐標(biāo)系時(shí)間序列圖+繪制金字塔圖,詳細(xì)的內(nèi)容需要的小伙伴可以參考一下下面文章內(nèi)容

1.繪制發(fā)散型柱狀圖

python繪制發(fā)散型柱狀圖,展示單個(gè)指標(biāo)的變化的順序和數(shù)量,在柱子上添加了數(shù)值文本。

實(shí)現(xiàn)代碼:

import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings(action='once')
df = pd.read_csv("C:\工作\學(xué)習(xí)\數(shù)據(jù)雜壇/datasets/mtcars.csv")
x = df.loc[:, ['mpg']]
df['mpg_z'] = (x - x.mean()) / x.std()
df['colors'] = ['red' if x < 0 else 'green' for x in df['mpg_z']]
df.sort_values('mpg_z', inplace=True)
df.reset_index(inplace=True)
# Draw plot
plt.figure(figsize=(10, 6), dpi=80)
plt.hlines(y=df.index,
? ? ? ? ? ?xmin=0,
? ? ? ? ? ?xmax=df.mpg_z,
? ? ? ? ? ?color=df.colors,
? ? ? ? ? ?alpha=0.8,
? ? ? ? ? ?linewidth=5)
for x, y, tex in zip(df.mpg_z, df.index, df.mpg_z):
? ? t = plt.text(x, y, round(tex, 2), horizontalalignment='right' if x < 0 else 'left',

? ? ? ? ? ? ? ? ?verticalalignment='center', fontdict={'color':'black' if x < 0 else 'black', 'size':10})

# Decorations

plt.gca().set(ylabel='$Model', xlabel='$Mileage')
plt.yticks(df.index, df.cars, fontsize=12)
plt.xticks(fontsize=12)
plt.title('Diverging Bars of Car Mileage')
plt.grid(linestyle='--', alpha=0.5)
plt.show()

實(shí)現(xiàn)效果:

2.繪制帶誤差陰影的時(shí)間序列圖

實(shí)現(xiàn)功能:

python繪制帶誤差陰影的時(shí)間序列圖。

實(shí)現(xiàn)代碼:

from scipy.stats import sem
import pandas as pd
import matplotlib.pyplot as plt
# Import Data
df_raw = pd.read_csv('F:\數(shù)據(jù)雜壇\datasets\orders_45d.csv',
? ? ? ? ? ? ? ? ? ? ?parse_dates=['purchase_time', 'purchase_date'])

# Prepare Data: Daily Mean and SE Bands
df_mean = df_raw.groupby('purchase_date').quantity.mean()
df_se = df_raw.groupby('purchase_date').quantity.apply(sem).mul(1.96)

# Plot
plt.figure(figsize=(10, 6), dpi=80)
plt.ylabel("Daily Orders", fontsize=12)
x = [d.date().strftime('%Y-%m-%d') for d in df_mean.index]
plt.plot(x, df_mean, color="#c72e29", lw=2)
plt.fill_between(x, df_mean - df_se, df_mean + df_se, color="#f8f2e4")

# Decorations
# Lighten borders
plt.gca().spines["top"].set_alpha(0)
plt.gca().spines["bottom"].set_alpha(1)
plt.gca().spines["right"].set_alpha(0)
plt.gca().spines["left"].set_alpha(1)
plt.xticks(x[::6], [str(d) for d in x[::6]], fontsize=12)
plt.title("Daily Order Quantity of Brazilian Retail with Error Bands (95% confidence)",fontsize=14)

# Axis limits
s, e = plt.gca().get_xlim()
plt.xlim(s, e - 2)
plt.ylim(4, 10)

# Draw Horizontal Tick lines
for y in range(5, 10, 1):
? ? plt.hlines(y,
? ? ? ? ? ? ? ?xmin=s,
? ? ? ? ? ? ? ?xmax=e,
? ? ? ? ? ? ? ?colors='black',
? ? ? ? ? ? ? ?alpha=0.5,
? ? ? ? ? ? ? ?linestyles="--",
? ? ? ? ? ? ? ?lw=0.5)

plt.show()

實(shí)現(xiàn)效果:

3.繪制雙坐標(biāo)系時(shí)間序列圖

實(shí)現(xiàn)功能:

python繪制雙坐標(biāo)系(雙變量)時(shí)間序列圖。

實(shí)現(xiàn)代碼:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# Import Data
df = pd.read_csv("F:\數(shù)據(jù)雜壇\datasets\economics.csv")

x = df['date']
y1 = df['psavert']
y2 = df['unemploy']

# Plot Line1 (Left Y Axis)
fig, ax1 = plt.subplots(1, 1, figsize=(12, 6), dpi=100)
ax1.plot(x, y1, color='tab:red')

# Plot Line2 (Right Y Axis)
ax2 = ax1.twinx() ?# instantiate a second axes that shares the same x-axis
ax2.plot(x, y2, color='tab:blue')

# Decorations
# ax1 (left Y axis)
ax1.set_xlabel('Year', fontsize=18)
ax1.tick_params(axis='x', rotation=70, labelsize=12)
ax1.set_ylabel('Personal Savings Rate', color='#dc2624', fontsize=16)
ax1.tick_params(axis='y', rotation=0, labelcolor='#dc2624')
ax1.grid(alpha=.4)

# ax2 (right Y axis)
ax2.set_ylabel("Unemployed (1000's)", color='#01a2d9', fontsize=16)
ax2.tick_params(axis='y', labelcolor='#01a2d9')
ax2.set_xticks(np.arange(0, len(x), 60))
ax2.set_xticklabels(x [::60], rotation=90, fontdict={'fontsize': 10})
ax2.set_title(
? ? "Personal Savings Rate vs Unemployed: Plotting in Secondary Y Axis",
? ? fontsize=18)
fig.tight_layout()
plt.show()

實(shí)現(xiàn)效果:

4.繪制金字塔圖

實(shí)現(xiàn)功能:

python繪制金字塔圖,一種排過(guò)序的分組水平柱狀圖barplot,可很好展示不同分組之間的差異,可可視化逐級(jí)過(guò)濾或者漏斗的每個(gè)階段。

實(shí)現(xiàn)代碼:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Read data
df = pd.read_csv("D:\數(shù)據(jù)雜壇\datasets\email_campaign_funnel.csv")

# Draw Plot
plt.figure()
group_col = 'Gender'
order_of_bars = df.Stage.unique()[::-1]
colors = [
? ? plt.cm.Set1(i / float(len(df[group_col].unique()) - 1))
? ? for i in range(len(df[group_col].unique()))
]

for c, group in zip(colors, df[group_col].unique()):
? ? sns.barplot(x='Users',
? ? ? ? ? ? ? ? y='Stage',
? ? ? ? ? ? ? ? data=df.loc[df[group_col] == group, :],
? ? ? ? ? ? ? ? order=order_of_bars,
? ? ? ? ? ? ? ? color=c,
? ? ? ? ? ? ? ? label=group)

# Decorations
plt.xlabel("$Users$")
plt.ylabel("Stage of Purchase")
plt.yticks(fontsize=12)
plt.title("Population Pyramid of the Marketing Funnel", fontsize=18)
plt.legend()
plt.savefig('C:\工作\學(xué)習(xí)\數(shù)據(jù)雜壇\素材\\0815\金字塔', dpi=300, bbox_inches = 'tight')
plt.show()

實(shí)現(xiàn)效果:

到此這篇關(guān)于python繪制發(fā)散型柱狀圖+誤差陰影時(shí)間序列圖+雙坐標(biāo)系時(shí)間序列圖+繪制金字塔圖的文章就介紹到這了,更多相關(guān)Python圖繪制內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python操作Excel插入刪除行的方法

    Python操作Excel插入刪除行的方法

    今天小編就為大家分享一篇Python操作Excel插入刪除行的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • python使用for...else跳出雙層嵌套循環(huán)的方法實(shí)例

    python使用for...else跳出雙層嵌套循環(huán)的方法實(shí)例

    這篇文章主要給大家介紹了關(guān)于python使用for...else跳出雙層嵌套循環(huán)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用python具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • Python字符編碼判斷方法分析

    Python字符編碼判斷方法分析

    這篇文章主要介紹了Python字符編碼判斷方法,結(jié)合實(shí)例形式分析了Python字符編碼的判斷技巧,并給出了chardet的安裝與使用方法,需要的朋友可以參考下
    2016-07-07
  • Python源碼學(xué)習(xí)之PyObject和PyTypeObject

    Python源碼學(xué)習(xí)之PyObject和PyTypeObject

    今天給大家?guī)?lái)的是關(guān)于Python源碼的相關(guān)知識(shí)學(xué)習(xí),文章圍繞著PyObject和PyTypeObject展開(kāi),文中有非常詳細(xì)的介紹及代碼示例,需要的朋友可以參考下
    2021-06-06
  • Windows10+anacond+GPU+pytorch安裝詳細(xì)過(guò)程

    Windows10+anacond+GPU+pytorch安裝詳細(xì)過(guò)程

    這篇文章主要介紹了Windows10+anacond+GPU+pytorch安裝詳細(xì)過(guò)程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • python中二維陣列的變換實(shí)例

    python中二維陣列的變換實(shí)例

    這篇文章主要介紹了python中二維陣列的變換實(shí)例,通過(guò)對(duì)比兩種不同的方法分析了二維陣列變換的實(shí)現(xiàn)方法,需要的朋友可以參考下
    2014-10-10
  • python機(jī)器學(xué)習(xí)樸素貝葉斯算法及模型的選擇和調(diào)優(yōu)詳解

    python機(jī)器學(xué)習(xí)樸素貝葉斯算法及模型的選擇和調(diào)優(yōu)詳解

    這篇文章主要為大家介紹了python機(jī)器學(xué)習(xí)樸素貝葉斯及模型的選擇和調(diào)優(yōu)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步
    2021-11-11
  • python兩種遍歷字典(dict)的方法比較

    python兩種遍歷字典(dict)的方法比較

    這篇文章主要介紹了python兩種遍歷字典(dict)的方法比較,同時(shí)介紹了dict遍歷中帶括號(hào)與不帶括號(hào)的性能問(wèn)題,需要的朋友可以參考下
    2014-05-05
  • pyinstaller打包后偶爾出現(xiàn)黑窗口一閃而過(guò)的問(wèn)題及解決

    pyinstaller打包后偶爾出現(xiàn)黑窗口一閃而過(guò)的問(wèn)題及解決

    這篇文章主要介紹了pyinstaller打包后偶爾出現(xiàn)黑窗口一閃而過(guò)的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • keras 簡(jiǎn)單 lstm實(shí)例(基于one-hot編碼)

    keras 簡(jiǎn)單 lstm實(shí)例(基于one-hot編碼)

    這篇文章主要介紹了keras 簡(jiǎn)單 lstm實(shí)例(基于one-hot編碼),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07

最新評(píng)論

老河口市| 上高县| 兰溪市| 禹城市| 驻马店市| 漳平市| 团风县| 务川| 安乡县| 青浦区| 武山县| 孟村| 奉化市| 萨嘎县| 阳西县| 连城县| 南安市| 永安市| 江都市| 进贤县| 固镇县| 平潭县| 嘉荫县| 娱乐| 临汾市| 宝清县| 公安县| 禹城市| 平遥县| 鹤庆县| 邢台市| 陆川县| 永春县| 大新县| 怀仁县| 会同县| 盐边县| 志丹县| 昆明市| 庄浪县| 南溪县|