下面的代碼生成此圖。我想知道是否有辦法將 value1 和 value2 之間的線變成箭頭,指向 1 到 2 的方向,從藍色到綠色(在這種情況下,沒有一個藍色低于綠色)。

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Create a dataframe
value1=np.random.uniform(size=20)
value2=value1 np.random.uniform(size=20)/4
df = pd.DataFrame({'group':list(map(chr, range(65, 85))), 'value1':value1 , 'value2':value2 })
# Reorder it following the values of the first value:
ordered_df = df.sort_values(by='value1')
my_range=range(1,len(df.index) 1)
# The horizontal plot is made using the hline function
plt.hlines(y=my_range, xmin=ordered_df['value1'], xmax=ordered_df['value2'], color='grey', alpha=0.4)
plt.scatter(ordered_df['value1'], my_range, color='skyblue', alpha=1, label='value1')
plt.scatter(ordered_df['value2'], my_range, color='green', alpha=0.4 , label='value2')
plt.legend()
# Add title and axis names
plt.yticks(my_range, ordered_df['group'])
plt.title("Comparison of the value 1 and the value 2", loc='left')
plt.xlabel('Value of the variables')
plt.ylabel('Group')
# Show the graph
plt.show()
uj5u.com熱心網友回復:
您可以使用
uj5u.com熱心網友回復:
- 多個箭頭
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/331258.html標籤:Python 熊猫 matplotlib 散点图
