简体   繁体   中英

Contour plots in python with time on X-Axis

I wish to do a contour plot in python with the sample data given below:- X-Axis(Time) Y-Axis(D) Z-Axis(C) 15:18:48 10 26 15:18:49 11 28 15:18:50 13 30. . . . . . Given below is my code

enter code here
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
load_var=pd.read_excel(r'path\file.xlsx')
x=pd.DataFrame(load_var['Time'])
y=pd.DataFrame(load_var['D'])
z=pd.DataFrame(load_var['C'])
plt.contour(x,y,z)

Error: TypeError: unhashable type: 'numpy.ndarray' Kindly clear the following doubts: 1] How to create the mesh-grid using X-axis as time and Y-axis as values mentioned under 'D'? 2] Please Suggest the updations in the code.

Thank you.

As the documentation states, the 'Z' parameter of plt.contour should be with size of (M, N) : if x, y have 500 values, the size of z should be (500, 2).

You supply z which is a single column, aka (500, 1). That is not how the contours plot works.

PS - no need in pd.DataFrame(load_var['C']) , you can directly work with load_var['C'] . Example:

df = pd.DataFrame({'x': [0.2, 0.1, 0.5], 'y': [34.2, 73.1, 43.5], 'z':[105, 108, 101], 'z2':[105, 108, 101], 'z3':[105, 108, 101]})
plt.contour(df.x,df.y, df[['z', 'z2', 'z3']])
plt.show()

output: 轮廓示例

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM