第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

組合條形圖和線圖的問題(python)

組合條形圖和線圖的問題(python)

炎炎設(shè)計(jì) 2022-08-25 15:21:05
我有這樣的數(shù)據(jù)幀:df_meshX_min_select = pd.DataFrame({'Number of Elements'  : [5674, 8810,13366,19751,36491],'Time (a)'            : [42.14, 51.14, 55.64, 55.14, 56.64],'Different Result(Temperature)' : [0.083849, 0.057309, 0.055333, 0.060516, 0.035343]})我試圖在同一圖中組合條形圖(元素?cái)?shù)與不同結(jié)果)和線圖(元素?cái)?shù)與時(shí)間),但我發(fā)現(xiàn)了以下問題:在組合 2 個(gè)圖時(shí),x_value似乎不匹配,但是如果您看到數(shù)據(jù)框,則 x 值完全相同。我的期望是將這兩個(gè)圖組合成1個(gè)數(shù)字: 這是我做的代碼:import numpy as npimport pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltimport matplotlib.ticker as tickerdf_meshX_min_select = pd.DataFrame({    'Number of Elements'  : [5674, 8810,13366,19751,36491],    'Time (a)'            : [42.14, 51.14, 55.64, 55.14, 56.64],    'Different Result(Temperature)' : [0.083849, 0.057309, 0.055333, 0.060516, 0.035343]})x1= df_meshX_min_select["Number of Elements"]t1= df_meshX_min_select["Time (a)"]T1= df_meshX_min_select["Different Result(Temperature)"]#Create combo chartfig, ax1 = plt.subplots(figsize=(10,6))color = 'tab:green'#bar plot creationax1.set_title('Mesh Analysis', fontsize=16)ax1.set_xlabel('Number of elements', fontsize=16)ax1.set_ylabel('Different Result(Temperature)', fontsize=16)ax1 = sns.barplot(x='Number of Elements', y='Different Result(Temperature)', data = df_meshX_min_select)ax1.tick_params(axis='y')#specify we want to share the same x-axisax2 = ax1.twinx()color = 'tab:red'#line plot creationax2.set_ylabel('Time (a)', fontsize=16)ax2 = sns.lineplot(x='Number of Elements', y='Time (a)', data = df_meshX_min_select, sort=False, color=color, ax=ax2)ax2.tick_params(axis='y', color=color)#show plotplt.show()任何人都可以幫我,請(qǐng)?
查看完整描述

2 回答

?
慕村225694

TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊

Seaborn 和 pandas 對(duì)條形圖(內(nèi)部編號(hào)為 0,1,2,...)使用分類 x 軸,對(duì)線圖使用浮點(diǎn)數(shù)。請(qǐng)注意,您的 x 值不是均勻分布的,因此條形圖之間會(huì)有奇怪的距離,或者不會(huì)與線圖中的 x 值對(duì)齊。


下面是一個(gè)使用標(biāo)準(zhǔn) matplotlib 來組合兩個(gè)圖形的解決方案。


import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

import matplotlib.ticker as ticker


df_meshx_min_select = pd.DataFrame({

    'number of elements': [5674, 8810, 13366, 19751, 36491],

    'time (a)': [42.14, 51.14, 55.64, 55.14, 56.64],

    'different result(temperature)': [0.083849, 0.057309, 0.055333, 0.060516, 0.035343]})

x1 = df_meshx_min_select["number of elements"]

t1 = df_meshx_min_select["time (a)"]

d1 = df_meshx_min_select["different result(temperature)"]


fig, ax1 = plt.subplots(figsize=(10, 6))

color = 'limegreen'

ax1.set_title('mesh analysis', fontsize=16)

ax1.set_xlabel('number of elements', fontsize=16)

ax1.set_ylabel('different result(temperature)', fontsize=16, color=color)

ax1.bar(x1, height=d1, width=2000, color=color)

ax1.tick_params(axis='y', colors=color)


ax2 = ax1.twinx()  # share the x-axis, new y-axis

color = 'crimson'

ax2.set_ylabel('time (a)', fontsize=16, color=color)

ax2.plot(x1, t1, color=color)

ax2.tick_params(axis='y', colors=color)


plt.show()

在此輸入圖像描述

查看完整回答
反對(duì) 回復(fù) 2022-08-25
?
紅糖糍粑

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超6個(gè)贊

我正在用線圖繪制一個(gè)箱線圖,即使我的兩個(gè)x軸相同,我也遇到了同樣的問題,所以我解決了將x軸特征轉(zhuǎn)換為類型字符串的問題:

df_meshX_min_select['Number of Elements'] = df_meshX_min_select['Number of Elements'].astype('string')

通過這種方式,情節(jié)使用seaborn工作:

在此輸入圖像描述


查看完整回答
反對(duì) 回復(fù) 2022-08-25
  • 2 回答
  • 0 關(guān)注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)