Pcolor ile matplotlib içinde ısı haritası?
Bu (FlowingDatagösterilen) gibi bir ısı haritası yapmak istiyorum:
Veri ama rasgele veri ve etiketler here, kaynak kullanımı iyi olurdu yani
import numpy
column_labels = list('ABCD')
row_labels = list('WXYZ')
data = numpy.random.rand(4,4)
İlgi haritası matplotlib kolay yeterli:
from matplotlib import pyplot as plt
heatmap = plt.pcolor(data)
Ve ben bile doğru bak colormap bir argüman bulundu: heatmap = plt.pcolor(data, cmap=matplotlib.cm.Blues)
Ama bunun ötesinde, sütun ve satır etiketlerini görüntülemek için nasıl çözemiyorum ve doğru yönde verileri (üst, alt, sol yerine sol kökenli) görüntüler.
heatmap.axes
(*8 örneğin*) işlemek için girişimleri başarısız oldu. Burada neyi kaçırıyorum?
GÜNCELLEME:
Paul H unutbu this question cevap (kim) sayesinde, güzel güzel çıkış var:
import matplotlib.pyplot as plt
import numpy as np
column_labels = list('ABCD')
row_labels = list('WXYZ')
data = np.random.rand(4,4)
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap=plt.cm.Blues)
# put the major ticks at the middle of each cell
ax.set_xticks(np.arange(data.shape[0]) 0.5, minor=False)
ax.set_yticks(np.arange(data.shape[1]) 0.5, minor=False)
# want a more natural, table-like display
ax.invert_yaxis()
ax.xaxis.tick_top()
ax.set_xticklabels(row_labels, minor=False)
ax.set_yticklabels(column_labels, minor=False)
plt.show()
Ve burada çıktı
CEVAP
Bu geç, ama burada flowingdata NBA ilgi haritası python benim uygulama.
:1/4/2014 . updated : herkese teşekkürler
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# ------------------------------------------------------------------------
# Filename : heatmap.py
# Date : 2013-04-19
# Updated : 2014-01-04
# Author : @LotzJoe >> Joe Lotz
# Description: My attempt at reproducing the FlowingData graphic in Python
# Source : http://flowingdata.com/2010/01/21/how-to-make-a-heatmap-a-quick-and-easy-solution/
#
# Other Links:
# http://stackoverflow.com/questions/14391959/heatmap-in-matplotlib-with-pcolor
#
# ------------------------------------------------------------------------
import matplotlib.pyplot as plt
import pandas as pd
from urllib2 import urlopen
import numpy as np
%pylab inline
page = urlopen("http://datasets.flowingdata.com/ppg2008.csv")
nba = pd.read_csv(page, index_col=0)
# Normalize data columns
nba_norm = (nba - nba.mean()) / (nba.max() - nba.min())
# Sort data according to Points, lowest to highest
# This was just a design choice made by Yau
# inplace=False (default) ->thanks SO user d1337
nba_sort = nba_norm.sort('PTS', ascending=True)
nba_sort['PTS'].head(10)
# Plot it out
fig, ax = plt.subplots()
heatmap = ax.pcolor(nba_sort, cmap=plt.cm.Blues, alpha=0.8)
# Format
fig = plt.gcf()
fig.set_size_inches(8, 11)
# turn off the frame
ax.set_frame_on(False)
# put the major ticks at the middle of each cell
ax.set_yticks(np.arange(nba_sort.shape[0]) 0.5, minor=False)
ax.set_xticks(np.arange(nba_sort.shape[1]) 0.5, minor=False)
# want a more natural, table-like display
ax.invert_yaxis()
ax.xaxis.tick_top()
# Set the labels
# label source:https://en.wikipedia.org/wiki/Basketball_statistics
labels = [
'Games', 'Minutes', 'Points', 'Field goals made', 'Field goal attempts', 'Field goal percentage', 'Free throws made', 'Free throws attempts', 'Free throws percentage',
'Three-pointers made', 'Three-point attempt', 'Three-point percentage', 'Offensive rebounds', 'Defensive rebounds', 'Total rebounds', 'Assists', 'Steals', 'Blocks', 'Turnover', 'Personal foul']
# note I could have used nba_sort.columns but made "labels" instead
ax.set_xticklabels(labels, minor=False)
ax.set_yticklabels(nba_sort.index, minor=False)
# rotate the
plt.xticks(rotation=90)
ax.grid(False)
# Turn off all the ticks
ax = plt.gca()
for t in ax.xaxis.get_major_ticks():
t.tick1On = False
t.tick2On = False
for t in ax.yaxis.get_major_ticks():
t.tick1On = False
t.tick2On = False
Çıkış bu gibi görünüyor:
Tüm bu kod here ile ipython bir dizüstü bilgisayar var. 'Taşma yüzden umarım birisi bu yararlı bulacaksınız. bir çok şey öğrendim
Hiçbir komplo pencere matplotlib içind...
Matplotlib arsa içinde sol ve sağ kena...
robots.txt içinde site haritası url...
Nasıl matplotlib içinde en boy oranını...
Matplotlib içinde ters colormap...