亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在直方圖矩陣 jupyter 上展開數據

在直方圖矩陣 jupyter 上展開數據

撒科打諢 2022-09-27 15:12:25
請注意,我是matplotlib的新手,我正在嘗試將直方圖中的數據分散開來,可以在下面看到。以下是我編碼的結果:我想實現的是:我嘗試分散箱子,但它只會降低頻率,而不會分散圖表。以下是我的代碼:#Loading dataurl = 'https://raw.githubusercontent.com/diggledoot/dataset/master/uber-raw-data-apr14.csv'latlong = pd.read_csv(url)#Rounding off data for more focused resultsn=2latlong['Lon']=[round(x,n) for x in latlong['Lon']]latlong['Lat']=[round(x,n) for x in latlong['Lat']]#Plotplt.figure(figsize=(8,6))plt.title('Rides based on latitude')plt.hist(latlong['Lat'],bins=100,color='cyan')plt.xlabel('Latitude')plt.ylabel('Frequency')plt.xticks(np.arange(round(latlong.Lat.min(),1),round(latlong.Lat.max(),1),0.1),rotation=45)plt.show()如何以與我想要實現的直方圖類似的方式分隔 x 刻度線?
查看完整描述

1 回答

?
UYOU

TA貢獻1878條經驗 獲得超4個贊

如果您這樣做


frequency, bins = np.histogram(latlong['Lat'], bins=20)

print(frequency)

print(bins)

你得到


[     1      7     12     18    301  35831 504342  22081   1256    580

     63     12      8      1      2      0      0      0      0      1]

[40.07   40.1725 40.275  40.3775 40.48   40.5825 40.685  40.7875 40.89

 40.9925 41.095  41.1975 41.3    41.4025 41.505  41.6075 41.71   41.8125

 41.915  42.0175 42.12  ]

你可以看到,有些計數與平均值相去甚遠。


您可以通過在指定的最小值和最大值之間剪切感興趣的變量來忽略那些遠離均值的條柱,然后繪制直方圖,如下所示


import pandas as pd

import matplotlib.pyplot as plt

import numpy as np

#Loading data

url = 'https://raw.githubusercontent.com/diggledoot/dataset/master/uber-raw-data-apr14.csv'

latlong = pd.read_csv(url)


#Plot

plt.figure(figsize=(8,6))

plt.title('Rides based on latitude')

plt.hist(np.clip(latlong['Lat'], 40.6, 40.9),bins=50,color='cyan')

plt.xlabel('Latitude')

plt.ylabel('Frequency')

plt.show()


查看完整回答
反對 回復 2022-09-27
  • 1 回答
  • 0 關注
  • 63 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號