Python Forum

Full Version: How to make a contour plot in python(matplotli)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Can some one help me. I want to make a contour plot let's say an example of my data below. I have height data and temperatur data in csv file for 4 day :
Output:
date 1 date 2 date 3 date 4 height temp height temp height temp height temp 9.3 28.0 8.7 27.6 10.0 26.0 9.5 26.8 9.7 27.3 9.3 26.8 12.8 25.5 10.8 25.9 10.0 26.8 10.8 25.9 13.1 25.3 11.4 25.0 10.6 26.5 12.7 24.4 14.8 24.7 12.9 24.2 12.8 26.0 13.5 23.8 15.2 24.3 13.6 23.4 13.3 25.7 17.8 22.7 16.8 23.7 14.0 22.6 16.8 25.4 18.9 22.4 17.9 23.3 14.7 22.0 17.2 24.6 20.0 21.0 18.6 23.0 15.9 21.3
And this is my script tried :

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as colors
import csv
import glob
import os


path = "C:/Users/SYIFAAZRA/Documents/belajar_wradlib/Skew-T/New/"
os.chdir(path)

filenames = glob.glob("*.csv")

dfs = []
for f in filenames:
    col_names = ['height', 'temp']
    df = pd.read_csv(f, delimiter=',',skiprows=7, usecols=[11, 21], names=col_names, na_values=['----'])
    df = df.dropna()
    
    max = df.height.idxmax()
    min = df.height.idxmin()
    df = df.loc[min:max, :]
    
    dfs.append(df)
    
df2 = pd.concat(dfs, ignore_index=False, axis=1)


fig = plt.figure()
ax = fig.add_subplot(111)

x = np.linspace(0,100, 50)
y = df['height']
X,Y = np.meshgrid(x, y)
Z = df['temp']
plt.show()
I want to make a contour plot which x= number of date, y=height data, z=temp data. Can someone suggest to me how to resolve my script above.