How can adjust the heatmap in matplotlib?
I have two files with one columns of numbers each one, and I've created a heatmap as you can see in the next figure:
I'm trying to adjust the heatmap that i've created for have a figure like this:
I mean, I want adjust the number of the colorbar between 0 and 1 as the figure above. And, I don't want to have space white on the bord of the axes. So, What is I need to change o add to the script, for doing this?
I'm using the next script. Thanks a lot for your support.
from matplotlib import ticker
import numpy as np
import numpy.random
import matplotlib.pyplot as plt
# Create data
x = open("file1.txt").read().splitlines()
y = open("file2.txt").read().splitlines()
f = np.random.normal(x).astype(np.float)
g = np.random.normal(y).astype(np.float)
# Create heatmap
heatmap, xedges, yedges = np.histogram2d(f, g, bins=(50,50))
extent = [xedges[0], xedges[1], yedges[0], yedges[1]]
#heatmap = plt.pcolor(np.histogram2d(f, g, bins=(100,100), cmap=cmap,norm=norm)
# Plot heatmap
plt.clf()
plt.title('heatmap example')
plt.ylabel('y')
plt.xlabel('x')
plt.imshow(heatmap, cmap='Blues', extent=extent)
cb = plt.colorbar()
tick_locator = ticker.MaxNLocator(nbins=10)
cb.locator = tick_locator
cb.update_ticks()
plt.show()
See also questions close to this topic

Creating multi colored scatterplot in Python
I have a pandas dataframe that has data I want to plot, but I'd like to change the color of the dot based on the sex of the animal. I've tried a bunch of different ways to get this to work. First I tried to index a dictionary based on the df column called 'Sex'
figure = plt.figure(figsize=(20, 6)) axes = figure.add_subplot(1, 2, 1) clr = {'M':'firebrick','F':'blueviolet', 'I':'beige'} axes.scatter( data[ "Whole Weight"], data['Shucked Weight'],color=clr[str(data['Sex'])]) axes.set_ylabel( "Shucked Weight") axes.set_xlabel( "Whole Weight") axes.set_title("Whole Weight vs. Shucked Weight") plt.show() plt.close()
That gives me a bunch of key errors. Next I tried to loop through the df and add the column manually based on a row value:
for x1 in data['Sex']: if x1 == 'M': print(x1,) data['color'] = 'firebrick' elif x1 == 'F': data['color'] = 'blueviolet' else: data['color'] = 'bisque1'
I tried to make a dictionary from scratch that had the values in them:
weight_dict = pd.DataFrame(dict(whole = data['Whole Weight'], shucked = data['Shucked Weight'], sex = data['Sex'], color= some if statement that choked))
I tried to use the np.where statement, but I have 3 options for sex (Male, Female, and Infant, abbreviated as M,F, I)
data['color'] = np.where(data.Sex == 'M', 'Firebrick', (data.Sex == 'F', 'blueviolet','beige'))
And finally I got this to work:
def label_color(row): if row['Sex'] == 'M': return 'firebrick' elif row['Sex'] == 'F': return 'blueviolet' else: return 'beige' data['color'] = data.apply(lambda row: label_color(row), axis=1)
but I wasn't all that satisfied with the solution. I really wanted the first solution to work where I just had a custom dictionary and looked it up during the call to axes.scatter, but the errors were just bizarre and not understandable.
Is there an easier solution to this madness?

Annotations dont show (matplotlib graph with datetime data)
Im trying to make this work with my code, where each data point gets annotated.
import datetime as dt import matplotlib.pyplot as plt import matplotlib.dates as mdates import numpy as np a = np.array([(1.5376248e+09, 48, 5682.47), (1.5376932e+09, 57, 5767.98), (1.5377112e+09, 57, 5767.98)]) time_test = a[:,0] # raw time data in unix time x = a[:,1] # x coordinate z = a[:,2] # text to annotate date_1 = np.vectorize(dt.datetime.fromtimestamp)(time_test) # makes a datetimeobject from unix timestamp date = np.vectorize(mdates.date2num)(date_1) # makes matplotlib date from datetime myFmt = mdates.DateFormatter('%d%m%Y') plt.gca().xaxis.set_major_formatter(myFmt) for rsi, date_1, close in zip(x, time_test, z): plt.annotate(close, xy = (date_1, rsi), xytext=(2, 2)) plt.ylim(40,70) plt.xticks(rotation = 45) plt.plot(date, x) plt.show()
I tried to copy the loop as closely as possible and now its at least errorfree, but also the annotations don't show.
All ideas appreciated. Cheers

Python looping issue with variable not being assigned to on certain iteration
I am new to Python, I am experiencing some bug where on a certain iteration a variable declared outside of a loop is not being assigned to only after a specific iteration.
Line 28 on the 8th iteration (x == 7)
interest
is miscalculated (probably not assigned to or something) and remains the same value for the rest of the iterations. The variable value seems to get stuck.import matplotlib.pyplot as plt import numpy as np loanAmount = 500000.0 interestRate = 3.5 loanTerm = 30.0 monthlyInterest = [] monthlyPrincipal = [] compoundingRate = float((((interestRate / 12) * 0.01) + 1)) loanTermMonths = float(loanTerm * 12) preInterestMonthly = loanAmount / loanTermMonths lastMonthWithInt = preInterestMonthly * compoundingRate i = 1 sum = 0.0 while i < loanTermMonths  1: lastMonthWithInt = lastMonthWithInt * compoundingRate sum += lastMonthWithInt i += 1 baseMonthly = sum / loanTermMonths interest = 0.0 principal = 0.0 x = 0 while x < loanTermMonths  1: interest = float((loanAmount  principal) * (compoundingRate  1)) principal = baseMonthly  interest monthlyInterest.append(interest) monthlyPrincipal.append(principal) x += 1 x1 = np.arange(1, loanTermMonths) y1 = np.array(monthlyInterest) x2 = np.arange(1, loanTermMonths) y2 = np.array(monthlyPrincipal) plt.plot(x1, y1, label = "Interest") plt.plot(x2, y2, label = "Principal") plt.xlabel('months') plt.ylabel('$') plt.show()

Computing binary representation of a natural number as a sequence in R
I am trying to write a function which computes the binary representation of a natural number as a sequence of 0 and 1. I wrote it like this:
binary< function(n) {if(n > 1) {binary(as.integer(n/2))} cat(n%%2)}
The output I get is of type NULL. I am trying to convert it to integers so I can put them in a vector but I am having difficulties. I also tried to convert it to type logical and I would get values TRUE and FALSE but I could not convert them then to 0 and 1 and put them into a vector. Any ideas how to do it?

Sorting an array of numbers containing duplicate values
I've an array containing duplicate numbers. I need to sort them without using multiple loops using javascript.
What is the best possible way to sort it?
Current array: [0, 1, 2, 0, 3, 4, 2, 1, 4, 3] Sorted array: [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]
I don't want to use the sort function.

How many 8 digit numbers are there which are both divisible by 18 and every digit is either a 1, 2 or 3?
Solving this problem using python involves making sure that all the individual digits of numbers between 10,000,000 and 99,999,999 are 1, 2 or 3 and if the numbers are also divisible by 18. The answer (win) is the number of times both these conditions are true.
This is what I have so far:
count=10000000 win=0 yes=False while(True): def check(): i=0 for i in range(0,7): if count[i]==1 or count[i]==2 or count[i]==3: yes=True else: return(False) return(yes) while True: if count%18==0 and check()==True: win+=1 print(win) count+=1 if count>99999999: exit()
Any help is greatly appreciated.

Adding importance of points in matplotlib heat map
I have two questions about matplotlib heat map.
1) Is possible to add importance of X and Y points to matplotlib heat map?
2) Is possible to draw coordinates without data by white color?
My Python map generation file looks like this:
import sys import os import numpy as np import pandas as pd import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt from scipy import stats csv_filename = 'heatmap_data.csv' df = pd.read_csv(csv_filename) red_df = df[df['type']=='red'] blue_df = df[df['type']=='blue'] def compute_KDE_from_pos(x_pos,y_pos): xmin = x_pos.min() xmax = x_pos.max() ymin = y_pos.min() ymax = y_pos.max() X, Y = np.mgrid[xmin:xmax:100j, ymin:ymax:100j] positions = np.vstack([X.ravel(), Y.ravel()]) values = np.vstack([x_pos, y_pos]) kernel = stats.gaussian_kde(values) Z = np.reshape(kernel(positions).T, X.shape) return Z Z_red = compute_KDE_from_pos(red_df.x_pos,red_df.y_pos) Z_blue = compute_KDE_from_pos(blue_df.x_pos,blue_df.y_pos) Z_diff = Z_blueZ_red fig, ax = plt.subplots() ax.imshow(np.rot90(Z_diff), cmap='RdBu', extent=[0, 100, 0, 100]) ax.plot(red_df.x_pos, red_df.y_pos, 'r.', markersize=2) ax.plot(blue_df.x_pos, blue_df.y_pos, 'b.', markersize=2) ax.set_xlim([0, 100]) ax.set_ylim([100, 0]) ax.axis('equal') plt.savefig("heatmap.png"
Heatmap data file (heatmap_data.csv):
x_pos,y_pos,type,importance 74,64,blue,0.011517617893368 68,64,blue,0.0041303878348102 32,64,red,0.049788810065569 8,64,red,0.12877712212094 88,64,red,0.0050599724578342 84,64,blue,0.00052412736663743 80,64,blue,0.020183850819375 78,64,blue,0.01297132988303 72,64,red,0.080092605800612 64,64,red,0.074683215098353 62,64,blue,0.011168199648943 58,64,red,0.030129086612831 56,64,red,0.085501996502871 54,64,red,0.042576289129223 50,64,red,0.0025580057348979 48,64,red,0.055198200767828 44,64,red,0.049788810065569 38,64,blue,0.0055840998244716 34,64,red,0.092714517439217 30,64,blue,0.025593241521634 28,64,red,0.07107695463018 26,64,red,0.0099452357934559 22,64,blue,0.043624543862498 20,64,blue,0.031002632223893 18,64,red,0.038795319538838 16,64,blue,0.023790111287548 12,64,blue,0.030827923101681 94,64,red,0.044728837607734 90,64,red,0.042750998251436 82,64,blue,0.066890527783408 76,64,blue,0.015123878361541 70,64,blue,0.045427674096584 66,64,blue,0.018206011463076 60,64,red,0.060607591470087 46,64,red,0.01227249339418 14,64,red,0.0048852633356217 92,64,red,0.041122577139562 52,64,blue,0.007387230058558 36,64,blue,0.025418532399422 4,64,red,0.02326598392091 86,64,blue,0.021812271931249 42,64,red,0.0034315513459603 40,64,blue,0.0037809695903852 24,64,blue,0.092134351060618 50,24,blue,0.034552853680104 92,24,red,0.021462853686824 86,24,red,0.039319446905475 82,24,red,0.0088409420482194 74,24,red,0.0088409420482194 66,24,red,0.015878753862352 64,24,blue,0.023790111287548 60,24,red,0.017332465852014 56,24,red,0.049089973576719 54,24,red,0.10661543194527 52,24,red,0.03140808948028 48,24,red,0.051067812933018 46,24,red,0.0081421055593695 44,24,red,0.097425071652626 42,24,blue,0.043624543862498 40,24,red,0.080092605800612 36,24,blue,0.034434183569854 10,24,red,0.044728837607734 34,24,red,0.03553847731509 84,24,red,0.019659723452738 80,24,red,0.010644072282306 58,24,red,0.040423740650712 32,24,blue,0.00017470912221247 30,24,red,0.046357258719608 8,24,red,0.019659723452738 90,24,red,0.021462853686824 70,24,red,0.026697535266871 62,24,blue,0.050662355676631 38,24,blue,0.021812271931249 68,24,blue,0.01640288122899 14,68,red,0.01570404474014 18,68,red,0.058629752113788 20,68,red,0.055023491645615 38,68,red,0.082070445156911 10,68,red,0.033735347081004 24,68,blue,0.0023272576007238 28,68,red,0.044379419363309 36,68,red,0.023091274798698 50,68,red,0.018960886963888 52,68,red,0.057001331001914 56,68,blue,0.0039556787125977 68,68,blue,0.052465485910717 72,68,blue,0.016577590351202 74,68,red,0.062061303459748 76,68,blue,0.038215153160239 78,68,red,0.044379419363309 80,68,red,0.010469363160093 82,68,red,0.010294654037881 84,68,red,0.033560637958791 86,68,red,0.0086662329260069 90,68,blue,0.00017470912221247 66,68,red,0.055198200767828 70,68,blue,0.00034941824442495 8,68,red,0.0034315513459603 12,68,blue,0.0091903602926443 16,68,blue,0.018380720585289 62,68,red,0.035363768192878 26,68,blue,0.039843574272113 32,68,blue,0.021812271931249 34,68,blue,0.010993490526731 40,68,red,0.021288144564612 44,68,blue,0.0055840998244716 46,68,blue,0.010993490526731 48,68,blue,0.0091903602926443 22,68,blue,0.048859225442545 30,68,blue,0.012796620760817 58,68,red,0.0050599724578342 88,68,blue,0.0055840998244716 84,68,red,0.028151247256532 22,68,red,0.14087490639291 90,68,red,0.015878753862352 70,68,red,0.040773158895137 68,68,red,0.0050599724578342 66,68,red,0.030129086612831 64,68,red,0.037166898426964 62,68,red,0.0086662329260069 58,68,red,0.039144737783263 54,68,blue,0.0055840998244716 52,68,red,0.030129086612831 50,68,red,0.077940057322101 48,68,blue,0.012796620760817 44,68,red,0.030129086612831 40,68,red,0.066016982172346 38,68,red,0.06421385193826 34,68,red,0.037341607549176 32,68,red,0.0050599724578342 28,68,red,0.01227249339418 24,68,blue,0.025593241521634 20,68,red,0.049614100943356 18,68,blue,0.013146039005242 14,68,red,0.01570404474014 76,68,red,0.022741856554273 74,68,red,0.056826621879702 72,68,red,0.037166898426964 26,68,blue,0.0075619391807704 94,68,red,0.042925707373648 82,68,red,0.024544986788359 56,68,blue,0.021812271931249 46,68,blue,0.014599750994903 42,68,blue,0.010993490526731 8,68,red,0.096495487029602 80,68,red,0.0032568422237478 30,68,blue,0.021812271931249 16,68,blue,0.029024792867594 10,68,blue,0.0019778393562988 86,68,blue,0.007387230058558 78,68,blue,0.038040444038026 12,68,blue,0.027221662633508 4,68,red,0.02326598392091 80,64,red,0.10335858972152 14,64,red,0.026522826144658 12,64,blue,0.00034941824442495 32,64,blue,0.01297132988303 34,64,red,0.049788810065569 38,64,red,0.028325956378745 44,64,blue,0.0021525484785113 46,64,red,0.0032568422237478 50,64,blue,0.040192992516538 54,64,red,0.0086662329260069 56,64,red,0.010294654037881 58,64,red,0.01227249339418 60,64,red,0.040947868017349 68,64,red,0.013726205383841 70,64,blue,0.011168199648943 74,64,red,0.0048852633356217 78,64,blue,0.057874876612976 82,64,red,0.020938726320187 84,64,red,0.1803690624206 86,64,red,0.049788810065569 88,64,blue,0.0055840998244716 10,64,red,0.0050599724578342 16,64,red,0.060258173225662 18,64,blue,0.014774460117116 26,64,blue,0.036412022926152 30,64,blue,0.041646704506199 36,64,red,0.037341607549176 40,64,blue,0.012796620760817 52,64,blue,0.020009141697163 64,64,blue,0.032631053335767 66,64,red,0.055198200767828 72,64,red,0.012097784271967 76,64,blue,0.041821413628412 20,64,blue,0.038215153160239 22,64,red,0.017332465852014 24,64,blue,0.079512439422013 42,64,red,0.0068631026919206 62,64,blue,0.025593241521634 92,64,red,0.012447202516392 66,32,red,0.089282966093256 50,32,red,0.068400278785031 44,32,red,0.05124252205523 84,32,red,0.026697535266871 82,32,red,0.05537290989004 72,32,red,0.051766649421867 64,32,red,0.0014537119896614 62,32,red,0.03897002866105 60,32,blue,0.007387230058558 48,32,red,0.051417231177442 46,32,red,0.033560637958791 40,32,blue,0.00034941824442495 38,32,blue,0.0021525484785113 36,32,red,0.03553847731509 32,32,blue,0.0039556787125977 30,32,red,0.026697535266871 28,32,blue,0.007387230058558 22,32,red,0.030303795735043 94,32,red,0.042925707373648 76,32,red,0.037516316671389 74,32,red,0.010644072282306 68,32,red,0.0050599724578342 58,32,red,0.0032568422237478 56,32,red,0.046007840475183 52,32,blue,0.021986981053461 34,32,blue,0.01640288122899 24,32,red,0.026697535266871 20,32,red,0.0016284211118739 12,32,red,0.0034315513459603 8,32,red,0.033910056203216 80,32,red,0.010644072282306 54,32,blue,0.021986981053461 42,32,blue,0.023615402165335 18,32,blue,0.0055840998244716 16,32,red,0.0052346815800466 4,32,red,0.017856593218651 10,32,red,0.0034315513459603 46,24,red,0.056477203635277 48,24,red,0.054848782523403 50,24,red,0.12720474002103 54,24,red,0.013551496261629 26,24,red,0.012447202516392 32,24,red,0.042750998251436 36,24,red,0.06421385193826 38,24,blue,0.032631053335767 40,24,red,0.024719695910572 52,24,red,0.14610958797296 56,24,blue,0.00087354561106237 60,24,red,0.01570404474014 64,24,blue,0.027221662633508 74,24,red,0.007037811814133 78,24,red,0.0052346815800466 16,24,red,0.016053462984565 44,24,blue,0.013146039005242 58,24,blue,0.068693658017495 62,24,blue,0.03623731380394 22,24,red,0.0052346815800466 28,24,red,0.010644072282306 30,24,red,0.017681884096439 42,24,red,0.0048852633356217 70,28,red,0.042750998251436 16,28,red,0.014250332750479 20,28,red,0.05537290989004 22,28,red,0.0034315513459603 34,28,red,0.040947868017349 40,28,red,0.073054793986479 42,28,blue,0.0095397785370693 50,28,red,0.026928283401045 56,28,red,0.018960886963888 58,28,red,0.085501996502871 60,28,red,0.0032568422237478 62,28,blue,0.030827923101681 64,28,red,0.0032568422237478 76,28,red,0.040947868017349 14,28,red,0.012447202516392 46,28,red,0.012097784271967 48,28,blue,0.057874876612976 52,28,red,0.0191355960861 54,28,blue,0.031002632223893 98,28,red,0.02326598392091 8,28,red,0.014250332750479 18,28,red,0.007037811814133 28,28,red,0.015878753862352 30,28,red,0.0068631026919206 32,28,blue,0.014599750994903 38,28,blue,0.023615402165335 82,28,red,0.012447202516392 90,28,red,0.019659723452738 36,28,blue,0.027221662633508 44,28,blue,0.054268616144804 68,28,blue,0.01640288122899 78,28,red,0.019659723452738 26,44,red,0.033735347081004 6,44,red,0.012447202516392 16,44,red,0.033735347081004 20,44,blue,0.0037809695903852 34,44,red,0.042750998251436 36,44,red,0.040773158895137 44,44,red,0.010469363160093 48,44,red,0.0032568422237478 50,44,blue,0.086899669480571 54,44,blue,0.032631053335767 58,44,red,0.060607591470087 66,44,red,0.014075623628266 68,44,blue,0.0091903602926443 76,44,red,0.058804461236 80,44,red,0.024894405032784 86,44,red,0.051766649421867 92,44,red,0.042925707373648 18,44,blue,0.010993490526731 40,44,blue,0.00017470912221247 42,44,red,0.083873575390997 74,44,blue,0.0057588089466841 88,44,red,0.030303795735043 24,44,blue,0.012796620760817 30,44,blue,0.023615402165335 60,44,red,0.015878753862352 78,44,blue,0.007387230058558 46,44,blue,0.0037809695903852 52,44,blue,0.012796620760817 56,44,blue,0.029024792867594 64,44,red,0.0052346815800466 12,60,red,0.024894405032784 14,60,blue,0.0019778393562988 16,60,red,0.019485014330525 20,60,red,0.0068631026919206 22,60,red,0.026522826144658 26,60,blue,0.020009141697163 34,60,red,0.0050599724578342 36,60,red,0.053569779655954 40,60,red,0.048160388953695 44,60,blue,0.010993490526731 50,60,blue,0.0077366483029829 58,60,red,0.067820112406432 62,60,red,0.028500665500957 64,60,red,0.051766649421867 68,60,red,0.01227249339418 76,60,red,0.0084915238037944 78,60,blue,0.010993490526731 86,60,red,0.037341607549176 84,60,red,0.010469363160093 10,60,red,0.016053462984565 24,60,blue,0.020009141697163 28,60,blue,0.0039556787125977 48,60,blue,0.0055840998244716 66,60,blue,0.00017470912221247 70,60,red,0.01227249339418 90,60,red,0.0016284211118739 30,60,blue,0.020009141697163 74,60,blue,0.0021525484785113 72,60,blue,0.025418532399422 88,52,red,0.033910056203216 86,52,red,0.026697535266871 84,52,red,0.039144737783263 82,52,red,0.019485014330525 80,52,blue,0.0091903602926443 76,52,red,0.0068631026919206 68,52,red,0.042750998251436 66,52,red,0.033735347081004 64,52,red,0.042750998251436 62,52,red,0.037341607549176 56,52,red,0.015878753862352 54,52,blue,0.025418532399422 48,52,red,0.0032568422237478 46,52,red,0.051591940299655 40,52,red,0.0032568422237478 38,52,red,0.047985679831482 34,52,red,0.017681884096439 32,52,red,0.03897002866105 22,52,blue,0.007387230058558 16,52,blue,0.0055840998244716 78,52,red,0.0086662329260069 60,52,red,0.01227249339418 52,52,red,0.033735347081004 44,52,blue,0.007387230058558 42,52,blue,0.023615402165335 36,52,red,0.01227249339418 24,52,blue,0.020009141697163 18,52,blue,0.018206011463076 8,52,red,0.039319446905475 6,52,red,0.019659723452738 74,52,blue,0.018206011463076 72,52,red,0.0014537119896614 70,52,red,0.0050599724578342 50,52,blue,0.059678006847063 12,52,red,0.010469363160093 58,52,red,0.017681884096439 26,52,blue,0.007387230058558 50,28,red,0.0029634629912845 92,28,red,0.02326598392091 78,28,red,0.0088409420482194 76,28,red,0.030303795735043 70,28,red,0.023091274798698 66,28,red,0.030129086612831 58,28,red,0.040598449772924 56,28,red,0.03140808948028 54,28,blue,0.029199501989807 52,28,red,0.07450850597614 44,28,blue,0.04920864368697 42,28,blue,0.0057588089466841 40,28,red,0.026522826144658 38,28,blue,0.03280576245798 34,28,red,0.040947868017349 22,28,red,0.0088409420482194 86,28,red,0.012447202516392 72,28,blue,0.0019778393562988 64,28,blue,0.018380720585289 48,28,blue,0.02396482040976 46,28,blue,0.047230804330671 30,28,blue,0.007387230058558 18,28,red,0.0034315513459603 6,28,red,0.017856593218651 90,28,red,0.039319446905475 62,28,red,0.013900914506054 26,28,red,0.0016284211118739 74,28,red,0.012447202516392 12,28,red,0.0088409420482194 20,48,red,0.017681884096439 18,48,red,0.01227249339418 26,48,blue,0.0091903602926443 36,48,red,0.031932216846917 38,48,red,0.049788810065569 44,48,red,0.089282966093256 46,48,blue,0.0021525484785113 48,48,blue,0.0021525484785113 50,48,red,0.036642771060327 52,48,red,0.037341607549176 56,48,red,0.062236012581961 74,48,red,0.0068631026919206 82,48,red,0.017507174974226 84,48,blue,0.0055840998244716 8,48,red,0.044728837607734 12,48,red,0.024894405032784 14,48,red,0.053395070533741 22,48,red,0.024719695910572 24,48,red,0.024719695910572 28,48,blue,0.021812271931249 34,48,red,0.014075623628266 70,48,red,0.0068631026919206 76,48,blue,0.012796620760817 78,48,red,0.01227249339418 58,48,blue,0.00034941824442495 64,48,red,0.01227249339418 66,48,blue,0.0055840998244716 72,48,blue,0.007387230058558 86,48,red,0.0052346815800466 32,48,blue,0.023615402165335 66,56,red,0.021113435442399 26,56,red,0.10876798042378 88,56,red,0.03210692596913 84,56,blue,0.00017470912221247 82,56,red,0.031932216846917 80,56,blue,0.0037809695903852 76,56,red,0.057001331001914 70,56,red,0.019485014330525 64,56,red,0.01227249339418 50,56,red,0.049439391821144 38,56,blue,0.0091903602926443 36,56,red,0.060607591470087 30,56,red,0.039144737783263 20,56,red,0.030129086612831 18,56,blue,0.023615402165335 14,56,red,0.037341607549176 12,56,red,0.033910056203216 10,56,red,0.046357258719608 58,56,blue,0.00017470912221247 52,56,blue,0.007387230058558 48,56,blue,0.012796620760817 40,56,red,0.046357258719608 22,56,red,0.03553847731509 6,56,red,0.016053462984565 90,56,red,0.026697535266871 72,56,blue,0.00017470912221247 60,56,red,0.019485014330525 54,56,red,0.0016284211118739 42,56,red,0.01227249339418 34,56,red,0.040947868017349 32,56,blue,0.034434183569854 16,56,red,0.0014537119896614 68,56,red,0.019485014330525 24,56,blue,0.039843574272113 70,36,red,0.06421385193826 24,36,red,0.0032568422237478 92,36,red,0.017856593218651 90,36,red,0.03210692596913 84,36,red,0.012447202516392 82,36,red,0.0052346815800466 76,36,blue,0.0037809695903852 72,36,red,0.0016284211118739 66,36,red,0.030129086612831 50,36,red,0.040074322406287 46,36,red,0.029954377490618 40,36,red,0.037341607549176 38,36,red,0.053395070533741 36,36,red,0.033735347081004 30,36,red,0.03897002866105 88,36,red,0.017856593218651 86,36,blue,0.0055840998244716 74,36,blue,0.023615402165335 68,36,blue,0.03623731380394 60,36,blue,0.027221662633508 58,36,blue,0.010993490526731 54,36,blue,0.025593241521634 48,36,blue,0.029199501989807 44,36,red,0.040598449772924 42,36,blue,0.0021525484785113 34,36,blue,0.020009141697163 28,36,red,0.044554128485522 52,36,red,0.042401580007011 56,36,blue,0.01297132988303 32,36,blue,0.032631053335767 12,36,red,0.058979170358213 64,36,blue,0.0091903602926443 62,36,blue,0.01640288122899 22,36,blue,0.01640288122899 20,36,blue,0.00017470912221247 6,36,red,0.017856593218651 68,72,red,0.039319446905475 30,72,red,0.042925707373648 86,72,red,0.039319446905475 76,72,red,0.035713186437303 72,72,red,0.016053462984565 60,72,red,0.017856593218651 56,72,red,0.014250332750479 36,72,red,0.044728837607734 26,72,red,0.041122577139562 24,72,red,0.010644072282306 22,72,red,0.035713186437303 20,72,red,0.042925707373648 18,72,red,0.060782300592299 12,72,red,0.017856593218651 10,72,red,0.014250332750479 6,72,red,0.046531967841821 70,72,red,0.017856593218651 50,72,red,0.007037811814133 42,72,red,0.019659723452738 34,72,red,0.019659723452738 14,72,red,0.016053462984565 90,72,red,0.019659723452738 44,72,red,0.017856593218651 48,72,red,0.017856593218651 86,60,red,0.01227249339418 90,60,red,0.014250332750479 88,60,blue,0.0037809695903852 82,60,blue,0.0039556787125977 74,60,blue,0.025418532399422 70,60,red,0.0191355960861 68,60,red,0.051591940299655 64,60,red,0.019310305208313 56,60,red,0.062410721704173 48,60,red,0.067820112406432 34,60,red,0.0050599724578342 30,60,red,0.03553847731509 28,60,red,0.019310305208313 22,60,blue,0.032631053335767 18,60,red,0.026522826144658 10,60,red,0.023091274798698 94,60,red,0.014250332750479 78,60,red,0.019485014330525 72,60,blue,0.0055840998244716 60,60,red,0.017681884096439 50,60,blue,0.067065236905621 40,60,red,0.096495487029602 38,60,blue,0.0091903602926443 36,60,blue,0.020009141697163 32,60,blue,0.014599750994903 26,60,blue,0.021986981053461 8,60,red,0.041122577139562 66,60,red,0.026522826144658 16,60,red,0.024719695910572 58,60,red,0.023091274798698 52,60,red,0.0016284211118739 46,60,red,0.024894405032784 42,60,blue,0.0055840998244716 14,60,red,0.051766649421867 54,60,red,0.010469363160093 24,60,blue,0.030827923101681 44,48,red,0.089108256971044 94,48,red,0.019659723452738 90,48,red,0.0034315513459603 84,48,red,0.0052346815800466 72,48,red,0.0032568422237478 68,48,red,0.0086662329260069 62,48,blue,0.038040444038026 60,48,red,0.096320777907389 58,48,red,0.058804461236 54,48,blue,0.018206011463076 52,48,red,0.053395070533741 50,48,blue,0.0062829363133215 48,48,red,0.010469363160093 34,48,red,0.026522826144658 32,48,blue,0.029024792867594 16,48,red,0.071251663752393 14,48,blue,0.00017470912221247 6,48,red,0.039319446905475 4,48,red,0.019659723452738 86,48,blue,0.0055840998244716 70,48,blue,0.020009141697163 64,48,blue,0.0075619391807704 42,48,blue,0.023615402165335 40,48,red,0.0050599724578342 30,48,red,0.033735347081004 22,48,red,0.0088409420482194 12,48,red,0.021288144564612 10,48,blue,0.007387230058558 92,48,red,0.010644072282306 76,48,red,0.0068631026919206 66,48,red,0.033735347081004 56,48,blue,0.0091903602926443 24,48,blue,0.007387230058558 78,48,red,0.019485014330525 8,32,red,0.007037811814133 20,32,red,0.0016284211118739 28,32,blue,0.0019778393562988 30,32,red,0.0068631026919206 32,32,red,0.0086662329260069 34,32,red,0.042750998251436 36,32,red,0.030129086612831 40,32,red,0.053395070533741 42,32,red,0.024719695910572 48,32,blue,0.03623731380394 50,32,red,0.0076179781927321 52,32,red,0.053395070533741 56,32,red,0.040773158895137 58,32,blue,0.018206011463076 60,32,red,0.037166898426964 68,32,red,0.031932216846917 70,32,red,0.040947868017349 76,32,red,0.0052346815800466 84,32,red,0.026697535266871 14,32,red,0.0088409420482194 22,32,red,0.010644072282306 24,32,blue,0.0019778393562988 38,32,red,0.017681884096439 44,32,red,0.076661054454652 62,32,blue,0.012796620760817 64,32,red,0.030129086612831 66,32,blue,0.012796620760817 80,32,red,0.037516316671389 6,32,red,0.010644072282306 72,32,red,0.007037811814133 88,32,red,0.039319446905475 74,32,blue,0.010993490526731 40,52,red,0.028325956378745 58,52,red,0.046182549597396 10,52,red,0.0052346815800466 16,52,red,0.046357258719608 22,52,red,0.069623242640519 24,52,blue,0.010993490526731 28,52,red,0.040947868017349 30,52,red,0.0048852633356217 36,52,red,0.055198200767828 38,52,red,0.094517647673303 52,52,red,0.03553847731509 54,52,red,0.0086662329260069 68,52,red,0.0050599724578342 82,52,blue,0.010993490526731 84,52,red,0.033735347081004 90,52,red,0.0034315513459603 14,52,red,0.017681884096439 18,52,blue,0.00017470912221247 20,52,blue,0.0091903602926443 34,52,red,0.021288144564612 44,52,red,0.033735347081004 56,52,red,0.0032568422237478 62,52,red,0.014075623628266 72,52,red,0.024894405032784 76,52,red,0.026522826144658 96,52,red,0.019659723452738 46,52,blue,0.021812271931249 64,52,blue,0.020009141697163 74,52,red,0.019485014330525 80,52,red,0.024894405032784 92,52,red,0.014250332750479 50,52,blue,0.07247462760788 70,52,blue,0.007387230058558 58,40,red,0.012097784271967 80,40,red,0.021288144564612 74,40,blue,0.0037809695903852 70,40,red,0.024719695910572 68,40,red,0.031757507724705 62,40,red,0.031932216846917 52,40,red,0.0050599724578342 48,40,blue,0.0057588089466841 44,40,red,0.049788810065569 40,40,red,0.066016982172346 34,40,red,0.026522826144658 32,40,red,0.033735347081004 28,40,blue,0.0055840998244716 24,40,red,0.078638893810951 16,40,blue,0.007387230058558 10,40,red,0.042750998251436 50,40,blue,0.0028513849673612 90,40,red,0.0088409420482194 78,40,red,0.075032633342778 66,40,blue,0.027221662633508 54,40,red,0.076661054454652 42,40,blue,0.0091903602926443 30,40,blue,0.018206011463076 22,40,red,0.014075623628266 56,40,blue,0.021812271931249 46,40,blue,0.00034941824442495 38,40,red,0.014075623628266 86,40,red,0.014250332750479 64,40,blue,0.038040444038026 26,40,blue,0.00034941824442495 12,40,blue,0.00017470912221247 4,40,red,0.021462853686824 62,40,red,0.026522826144658 12,40,red,0.0052346815800466 24,40,red,0.030129086612831 30,40,blue,0.021812271931249 38,40,blue,0.014599750994903 44,40,red,0.051591940299655 52,40,red,0.0086662329260069 54,40,red,0.047985679831482 58,40,red,0.03553847731509 64,40,red,0.014075623628266 70,40,red,0.024719695910572 76,40,red,0.0032568422237478 88,40,red,0.021288144564612 90,40,red,0.014250332750479 92,40,red,0.016053462984565 16,40,red,0.0052346815800466 26,40,blue,0.020009141697163 32,40,red,0.0050599724578342 34,40,blue,0.01640288122899 46,40,blue,0.0057588089466841 48,40,blue,0.0021525484785113 50,40,blue,0.041996122750624 56,40,red,0.01227249339418 72,40,blue,0.0091903602926443 10,40,red,0.017856593218651 20,40,red,0.053569779655954 36,40,blue,0.007387230058558 40,40,red,0.0032568422237478 42,40,red,0.028325956378745 84,40,blue,0.0019778393562988 50,20,red,0.056826621879702 42,20,red,0.062061303459748 56,20,red,0.029604959246194 58,20,red,0.11941205270609 52,20,blue,0.0021525484785113 46,20,red,0.10155545948744 40,20,blue,0.00052412736663743 16,20,red,0.016053462984565 8,20,red,0.019659723452738 60,20,red,0.060258173225662 66,20,red,0.0016284211118739 64,20,red,0.028325956378745 54,20,blue,0.052465485910717 44,20,blue,0.043624543862498 38,20,red,0.014075623628266 32,20,red,0.0016284211118739 30,20,red,0.014250332750479 12,20,red,0.021462853686824 76,20,red,0.016053462984565 36,20,blue,0.012796620760817 56,20,red,0.058280333869363 44,20,red,0.12121518294017 58,20,red,0.022567147432061 32,20,red,0.024894405032784 42,20,red,0.047985679831482 46,20,red,0.0032568422237478 50,20,red,0.033735347081004 60,20,red,0.035363768192878 68,20,red,0.0016284211118739 28,20,red,0.012447202516392 34,20,red,0.046357258719608 40,20,blue,0.041646704506199 62,20,red,0.01227249339418 36,20,blue,0.012796620760817 54,20,blue,0.038040444038026 26,20,red,0.014250332750479 88,20,red,0.021462853686824 44,36,blue,0.0057588089466841 50,36,blue,0.0010482547332749 4,36,red,0.021462853686824 14,36,red,0.0088409420482194 22,36,red,0.028500665500957 24,36,blue,0.0091903602926443 26,36,blue,0.0091903602926443 28,36,blue,0.012796620760817 36,36,blue,0.020009141697163 46,36,red,0.0050599724578342 52,36,red,0.017507174974226 56,36,red,0.019310305208313 62,36,blue,0.012796620760817 68,36,blue,0.0093650694148568 18,36,red,0.046357258719608 66,36,red,0.017507174974226 6,36,red,0.041122577139562 8,36,red,0.030303795735043 16,36,red,0.023091274798698 32,36,blue,0.00017470912221247 34,36,red,0.0052346815800466 42,36,red,0.0032568422237478 60,36,blue,0.007387230058558 70,36,blue,0.0021525484785113 74,36,red,0.017681884096439 76,36,blue,0.0055840998244716 84,36,red,0.014250332750479 20,36,red,0.03553847731509 12,36,red,0.0088409420482194 48,36,red,0.044379419363309 54,36,blue,0.029024792867594 58,36,blue,0.020009141697163 80,36,blue,0.010993490526731 82,36,red,0.0016284211118739 86,36,red,0.0052346815800466 10,36,red,0.012447202516392
Limits of graph are X (0 .. 100) and Y (0 .. 100).
Now it generates this heat map, but it's logicaly wrong. heatmap example
Heatmap should show positive and negative parts of hockey rink. Every data is shot ratio in certain coordinate.
Result should look's like this example. Red point should be red with emphasis to point importance and blue points should be blue with emphasis to importance of point (in CSV file). Points where are no data should be transparent (white). example of result heatmap

How can I feed in a visual attention map to a network?
I have a method that shows where to focus roughly on a given image, that is, it is not localization or segmentation labels but just a heat map that shows where what I look for in the image likely are. I am only hoping to increase classification accuracy as I don't have any other source of labels. I don't want to preprocess and crop the image according to the map and input in the network but I want to give higher prior to regions that my attention map shows. I have come across a lot of papers on selfguiding attention, soft attention learning, or using earlier activations as attention map, but I can not find more details on how I can implement a simple approach like I have mentioned.

Python: Change/customise colour maps in Seaborn
I've spent too much time looking into this, some tabs still open in my browser: Link1 Link2 Link3 Link4
I'm supposed to be working!
Anyway, my problem is: I use someone else's scripts to produce lots of heat maps which I then have to review and sort/assign:
Here's an example of one: HM sample
I need to be able to easily distinguish a 0.03 from a zero but as you can see they look virtually the same. Ideal solution would be: White(just zero's)YellowOrangeRed or White(just zero's)OrangeRed
The dev used 'YlOrRd' like so:
sns.heatmap(heat_map, annot=True, fmt=".2g", cmap="YlOrRd", linewidths=0.5, linecolor='black', xticklabels=xticks, yticklabels=yticks )
I've tried a bunch of the standard/default colour map options provided to no avail.
I don't have any real experience building colour maps and I don't want break something that's already working. Would anyone have any ideas?
Thanks
**I'm limited in what code/samples I can post due to it being work product.

color bar value spacing
I'm using a set of data which feature values that fall between .01% and 14% and I'm attempting to make a color bar which includes the values .01, .1, 1.5 and 14. I thought setting the values on the color bar would have them spread out equally from one color point to the next but I was wrong.. Here's what I currently have is there a simple command that would allow for these values to be shifted so they are separated by the same amount of space?
heat=plt.imshow(data, aspect='auto',interpolation='nearest', cmap=cm.afmhot) cbar = fig.colorbar(heat, ticks=[.1, 1,6, 14], orientation='vertical') plt.show()

Reduce horizontal colorbar padding
I'm trying to generate a plot with several axis, each one with their own colorbar (code below). If I use the default colorbar plotting I get too much horizontal spacing between the plot and the colorbar:
If I try to use the
make_axes_locatable()
method I get this horrible result:What is going on and how can I fix this?
import numpy as np from matplotlib import pyplot as plt import matplotlib.gridspec as gridspec from mpl_toolkits.axes_grid1 import make_axes_locatable # Random data to plot data = np.random.uniform(0., 1., (2, 100)) z = np.random.uniform(0., 10., 100) # Define figure fig = plt.figure(figsize=(30, 30)) gs = gridspec.GridSpec(12, 12) for i in range(2): ax = plt.subplot(gs[2 * i:2 + (2 * i), 0:8]) SC = plt.scatter(*data, c=z) # Colorbar 1 cbar = plt.colorbar() # Colorbar 2 # the_divider = make_axes_locatable(ax) # color_axis = the_divider.append_axes("right", size="1%", pad=0.) # cbar = plt.colorbar(SC, cax=color_axis) cbar.set_label("test", fontsize=15, labelpad=10) fig.tight_layout() plt.savefig('test.png', dpi=300, bbox_inches='tight')

Using pcolormesh with 3 one dimensional arrays in python
I am trying to use pcolormesh to plot 3 one dimensional arrays filled with coordinates and values. The arrays below are simply examples, yet they follow the same principle. I have 3 arrays, one for the x coordinate, one for the y coordinate, and one for their value (or z). Each index corresponds to a location. Index of 0 corresponds to x of 1, y of 1 and z of 6. This goes on for all indexes.
x = [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4] y = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4] z = [6,2,3,5,8,2,3,2,4,2,3,6,7,3,3,2] plt.figure() plt.pcolor(x,y,z) plt.colorbar() plt.show()
I've also tried...
x = [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4] y = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4] z = [6,2,3,5,8,2,3,2,4,2,3,6,7,3,3,2] N = np.sqrt(len(x)) N = int(N) np.reshape(x,(N,N)) np.reshape(y,(N,N)) np.reshape(z,(N,N)) plt.pcolormesh(x,y,c=z) plt.show()
Nothing seems to be working. Send Help