0

I am currently trying to produce a data viz of my experiment I did which involved xy scan files and then plotting them as a function of time. I have managed to get them into a pandas DataFrame that is (1027,281) in shape with the x axis as the index, time as the column labels and the values for the scan as the values in the df. The contour plot looks like this.

y = dftest.index.values
x = dftest.columns.values
z = dftest.values
X,Y = np.meshgrid(x,y)
z2 = np.ma.array(z)
z2_masked = np.ma.masked_where(z2 > 300, z2)
z2_masked = np.ma.masked_where(z2_masked < -5, z2_masked)
z3 = np.ma.filled(z2_masked, fill_value = 0)
plt.contourf(X, Y ,z3, 20, cmap = 'jet')
plt.colorbar()
plt.xlim(xmax = 175000)
plt.xticks(np.arange(0, 175000, step=50000))

Time resolved PXRD, x axis = time, y = diffraction angle:

enter image description here

Firstly that produces something that is the wrong way round, I would like the x value of the scan files to be the x axis, but instead it is the y axis. Then I would like to find a simple way of plotting this as a 3d contour map or surface. I think my problems lie in the shape of the data but I am not really sure how to correct it.

each of my DataFrame's looks like this:

           0.0       646.0       ...      181742.0   182390.0
x                                ...                         
0.996522   7.301625  3.914700    ...      8.224773   9.885618
1.000432  10.722788  7.379380    ...      8.474020  19.229299
1.004341   0.079724  5.567879    ...     -0.143427   2.684953
1.008251   4.738650  3.903460    ...     -1.162278   3.809588
1.012161   6.213206 -0.318955    ...      4.050190   1.454264
            ...       ...    ...           ...        ...
4.992126  -2.956039 -4.475446    ...     -2.816053  -4.556231
4.996036  -1.105434  1.274342    ...     -1.393612  -4.338330
4.999945  -0.536215  2.073975    ...     -2.727332  -1.083154
5.003855   5.983973  6.983155    ...      1.188320   3.657221
5.007765  -3.638785 -1.548692    ...     -5.225328  -2.164280

[1027 rows x 281 columns]
2
  • Possible duplicate of How to surface plot/3d plot from dataframe? Commented May 16, 2018 at 13:46
  • If you want the x axis to be the index why do you assign y = dftest.index.values? Wouldn't you want x = dftest.index.values? Commented May 16, 2018 at 16:35

1 Answer 1

1

To generate your contour plot (ignoring the masking for simplicity), doesn't this work?

x = dftest.index.values
y = dftest.columns.values
z = dftest.values
X,Y = np.meshgrid(x,y)
Z = z.T
plt.contourf(X,Y,Z,20,cmap='jet')
plt.colorbar()
plt.show()
Sign up to request clarification or add additional context in comments.

2 Comments

That's sorted out the contourf plot and the 3d plot. What is the: 'Z = z.T'? is that transpose? Thanks very much for your help
Yes, z.T simply transposes the array, so that the shapes are consistent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.