我有一个名为df_-comunidades的熊猫数据帧。在这里,我们可以看到类似头部的东西()
df_comunidades.head()
Tormenta Comunidad TIEPI Gustmax
0 ANA ANDALUCIA 0.050 130.2
1 ANA ARAGON 0.250 90.5
2 BRUNO ANDALUCIA 0.012 114.0
3 BRUNO CATALUNYA 0.023 78.2
4 KARINE ARAGON 3.500 80.2
5 ANA BALEARES 2.000 97.2
在我的散点图中,每个“Comunidad”都有不同的颜色,而且,我希望每个“Tormenta”都有不同的形状标记。我试过很多方法。。。其中一个类似于我用于颜色的方法。我还尝试了一个循环for i in range(len(markers)):
其中所有标记都保存在一个列表中 markers=['o','v','<','>','1','8','s','*','x','d']
我的稳定代码是:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# initialize list of lists
data = [['ANA', 'ANDALUCIA', 0.05, 130.2], ['ANA', 'ARAGON', 0.25, 90.5], ['BRUNO', 'ANDALUCIA', 0.012, 114], ['BRUNO', 'CATALUNYA', 0.023, 78.2],['KARINE', 'ARAGON', 3.5, 80.2], ['ANA', 'BALEARES', 2, 97.2]]
# Create the pandas DataFrame
df_comunidades = pd.DataFrame(data, columns = ['Tormenta', 'Comunidad', 'TIEPI', 'Gustmax'])
#I define every color for every "Comunidad"
colors = {'ANDALUCIA' : 'g',
'CATALUNYA' : 'y',
'BALEARES' : 'r',
'ARAGON' : 'c'}
c = [colors[comunid] for comunid in df_comunidades['Comunidad']]
plt.scatter(df_comunidades['TIEPI'], df_comunidades['Gustmax'], alpha=0.5, c=c)
ax = plt.subplot(1, 1, 1)
#code to title the axes and the plot:
ax.set_xlim([0,3])
ax.set_xlabel("TIEPI")
ax.set_ylabel("Max Gusts in community")
plt.title("Relation between max gusts and TIEPI in autonomous communities")
plt.savefig('max_tiepi-gusts_comunid.png',dpi=300)
我有这个。。。似乎广场比其他地方都高。。。但散射中的每个点都应该是一个“折磨”,颜色表示“Comunidad”。
在评论之后进行编辑,以便更加清晰
我想你只是在为这件事感到惋惜 颜色的序列, 然而,这只是一个单一的标记。 所以我们需要在N个点上循环。 (或者我们可以.groupby()如果我们想做的话,仅仅是呼吁折磨。)
两者之间似乎存在差异 “最小阵风”标签和 “古斯特马克斯”一栏
有许多markers可供选择。 你可以试试“v”、“s”、“p” 通过三面、四面、五面标记的过程
我做了这些更改以生成所附图表
相关问题 更多 >
编程相关推荐