0

I have a filled contour plot and I want to display the 1d slices of its two parameters. My contour plot was constructed by the following code:

import numpy as np
import matplotlib.pyplot as plt
import math

a=([8.0,9.0,10.0]) #a,b are the two axes in contour plot
b=([1.0,2.0,3.0])

c=[]
for i in range(0,len(a)):
    for j in range(0,len(b)):
        c.append(math.exp(a[i]/b[j]))  #c is the colour

c=np.array(c,dtype=float)
c=c.reshape(len(a),len(b))

y,x=np.meshgrid(b,a)
plt.contourf(x,y,c)

And my image looks like:

My contour plot

But the kind of plot I want is:

the kind of plot I want

Is there a way to do it with matplotlib?

Limona2000
  • 37
  • 6
  • Related: [Plot cross section through heat map](https://stackoverflow.com/questions/18920614/plot-cross-section-through-heat-map) and [Plotting two cross section intensity at the same time in one figure](https://stackoverflow.com/questions/59144464/plotting-two-cross-section-intensity-at-the-same-time-in-one-figure). You can use [scipy.interpolate.griddata](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html) to interpolate your coarse c values to a finer grid. – JohanC Mar 15 '22 at 23:21
  • @JohanC Thanks, I've had a look, but I need to plot an integrated cross section, i.e. get the distribution of z in a only, not just one line, and I'm not sure how to do that – Limona2000 Mar 19 '22 at 23:24
  • Maybe a plot of `c.sum(axis=0)` and one of `c.sum(axis=1)`? – JohanC Mar 19 '22 at 23:46
  • @JohanC Yeah, that's what I did, but apparently I would need to interpolate. I'll try the interpolation, thanks! – Limona2000 Mar 19 '22 at 23:56

0 Answers0