简体   繁体   English

Pandas python 3.7 上的热图

[英]HeatMap on pandas python 3.7

I'm trying to do a beautiful heatMap using pandas.我正在尝试使用熊猫做一个漂亮的热图。 The data is a csv file, is in the same folder of the script python.数据是一个csv文件,在脚本python的同一个文件夹中。

I got an error in my code, is easy:我的代码出错了,很简单:

File "<ipython-input-6-1b7ca215e6d0>", line 4
    fid = datadf u'/my_Path/File.csv'
                                                        ^
SyntaxError: invalid syntax

I think the important reason is not the syntax.我认为重要的原因不是语法。 So I need to your help ?所以我需要你的帮助?

My code is:我的代码是:

datadf = pd.read_csv("D:\my_Path\File.csv")
## Loading the data
fid = datadf u'/my_Path/File.csv'
key = u'dataset_key'

## Load the dataframe
df = pd.read_hdf(fid,key)

## Default plot ranges:
long_range = (datadf['long'].min(), datadf['long'].max())
lat_range = (datadf['lat'].min(), datadf['lat'].max())

## France plot ranges
long_range_fr = (-5,10)
lat_range_fr = (40,52)

## Visualization
### Custom functions
def bg(img):
    return tf.set_background(img,"black")

def create_image(long_range=long_range, lat_range=lat_range, w=800, h=800):
    cvs = ds.Canvas(x_range=long_range, y_range=lat_range, plot_height=h, plot_width=w)
    agg = cvs.points(df, 'lon', 'lat')
    return bg(tf.shade(agg, cmap = cm(Hot,0.2), how='eq_hist'))


### Statit plot
create_image(long_range=long_range_fr, lat_range=lat_range_fr)

A sample of my data:我的数据示例:

long        lat
-0.91655    43.456863
-0.495795   43.162117
-0.029272   43.097401
-0.108955   43.233845
-0.10237    43.207676
-0.096726   43.19257
-0.102862   43.216438
-0.1091     43.234241
-0.105826   43.225636
-0.096518   43.190247
-0.098496   43.19902
-0.079585   43.229698
-0.081321   43.232929
-0.079448   43.232937
-0.624699   43.364143
-0.429526   43.328094

As rightly mentioned by @Kristóf Varga seaborn heatmap can be used to find the appropriate solution.正如@Kristóf Varga 正确提到的,seaborn heatmap 可用于找到合适的解决方案。

A solution can be found over here: Using seaborn heatmap可以在此处找到解决方案: 使用 seaborn heatmap

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM