0

didn"t find an answer to that.

my data looks like that:

import pandas as pd    
mapDF = pd.DataFrame({u'N1': {0: 20,  1: 20,  2: 20,  3: 20,  4: 20,  5: 21,  6: 21,  7: 21,  8: 21,  9: 21,  10: 22,  11: 22,  12: 22,  13: 22,  14: 22,  15: 23,  16: 23,  17: 23,  18: 23,  19: 23,  20: 24,  21: 24,  22: 24,  23: 24,  24: 24}, 
    u'N2': {0: 50,  1: 51,  2: 52,  3: 53,  4: 54,  5: 50,  6: 51,  7: 52,  8: 53,  9: 54,  10: 50,  11: 51,  12: 52,  13: 53,  14: 54,  15: 50,  16: 51,  17: 52,  18: 53,  19: 54,  20: 50,  21: 51,  22: 52,  23: 53,  24: 54}, 
    u'optGain': {0: 1.119175,  1: 1.11189,  2: 1.0984430000000001,  3: 1.0648280000000001,  4: 1.0459499999999999,  5: 1.149848,  6: 1.154882,  7: 1.1460840000000001,  8: 1.096886,  9: 1.098012,  10: 1.1416869999999999,  11: 1.118763,  12: 1.118763,  13: 1.098276,  14: 1.068576,  15: 1.1165069999999999,  16: 1.128744,  17: 1.128744,  18: 1.1070770000000001,  19: 1.0678430000000001,  20: 1.100743,  21: 1.096325,  22: 1.087421,  23: 1.090177,  24: 1.089968}, 
    u'simGain': {0: 0.94936399999999999,  1: 0.94052000000000002,  2: 0.93819300000000005,  3: 0.90808299999999997,  4: 0.91296299999999997,  5: 0.94936399999999999,  6: 0.90771599999999997,  7: 0.90771599999999997,  8: 0.91296299999999997,  9: 0.85592699999999999,  10: 0.90232000000000001,  11: 0.90232000000000001,  12: 0.84629200000000004,  13: 0.75560000000000005,  14: 0.75560000000000005,  15: 0.92555200000000004,  16: 0.87239299999999997,  17: 0.87274600000000002,  18: 0.88428399999999996,  19: 0.83454799999999996,  20: 0.86954900000000002,  21: 0.88426899999999997,  22: 0.88746899999999995,  23: 0.82285200000000003,  24: 0.82285200000000003}})

and I am trying to make a contour map or surface plot where N1 , N2 are the x, y axis and optGain column is the value. tried with pylab or plotlib but none takes in the DF and all require meshing the data. This is cumbersome since I am not looking to plot a function but rather an already existing data. any help or pointers will be appreciated Thanks!

ayhan
  • 70,170
  • 20
  • 182
  • 203
Shuki
  • 97
  • 1
  • 3
  • 8

1 Answers1

1

See the answers to this question.

In general, you could do this with

import matplotlib.pyplot as plt

plt.scatter(mapDF.N1.values, mapDF.N2.values, c=mapDF.optGain.values, s=500)
plt.gray()

plt.show()

It will draw things in a continuous greys cale of the values.


Edit

The above will draw a grey scale scatter plot. As Syrtis Major notes in the comments, try tricontour for a 2d contour plot. With this function, note the colors parameter, specifically:

If a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified.

So you can use your mapDF.optGain.values to build RGB colors for different levels.

Community
  • 1
  • 1
Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
  • Thanks - though it's not a colormap, so i cannot see the values and with large datasets it will be hard to work with. – Shuki Mar 29 '16 at 13:13
  • Can you post a link to something that is a colormap? The terminology might be different. – Ami Tavory Mar 29 '16 at 13:14
  • OK - i think the correct term is a surface plot - but I wish to look at it as a 2D contour with colors (like topographic maps). I will rephrase the question - thanks again – Shuki Mar 29 '16 at 13:25
  • @Shuki See update. If you need further clarifications, feel free to comment. – Ami Tavory Mar 29 '16 at 13:51