python - Location of contour lines -
below code , plot:
import matplotlib import matplotlib.mlab mlab import matplotlib.cm cm import matplotlib.pyplot plt import numpy np %matplotlib inline delta = 0.00025 a=0 x = np.arange(0, 0.10, delta) y = np.arange(0, 0.1, delta) x, y = np.meshgrid(x, y) z = a*(x**2+y**2)+2*x*y manual_locations = [(0.1,0.1), (0.2,0.2), (0.3,0.3), (0.015, 0.015), (0.00255, 0.0025), (0.00005,0.00005)] line_widths = (1, 1, 1, 1, 1, 1) plt.figure() cs = plt.contour(x, y, z, 6, # add 6 contour lines linewidths=line_widths, # line widths colors = line_colours) # line colours plt.clabel(cs, inline=1, # add labels fontsize=10, # label font size manual=manual_locations) # label locations plt.title('indifference map') # title plt.show()
it seems manual_locations nothing, python picks equally spaced contour lines automatically. while want investigate more details around 0. how can see more curves/contour lines converging (0,0)? in advance.
the easiest way explore parts of data in more details levels
. sets z-values examine, , in question phrase (x,y) location inspect, it's bit backwards how contour
works specify location points directly.
you inspect (0,0) region changing boundaries of plot appropriately.
below, use log values levels
, linear values work equally well, far more common, , easier interpret. log values emphasis part of plot you're interested in.
import matplotlib import matplotlib.mlab mlab import matplotlib.cm cm import matplotlib.pyplot plt import numpy np #%matplotlib inline delta = 0.00025 a=0 x = np.arange(0, 0.10, delta) y = np.arange(0, 0.1, delta) x, y = np.meshgrid(x, y) z = a*(x**2+y**2)+2*x*y manual_locations = [(0.1,0.1), (0.2,0.2), (0.3,0.3), (0.015, 0.015), (0.00255, 0.0025), (0.00005,0.00005)] line_widths = (1, 1, 1, 1, 1, 1) plt.figure() cs = plt.contour(x, y, z, 6, # add 6 contour lines linewidths=line_widths, #levels=np.linspace(0, .003, 20)) levels=np.logspace(-5, -2, 20)) plt.clabel(cs, inline=1, # add labels fontsize=10, fmt="%.5f") plt.title('indifference map') # title plt.show()
if need contour @ specific location, put (x,y) values location equation calculate z-value @ location, , use value 1 of values in levels
argument.
Comments
Post a Comment