• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to make a contour plot in Python?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear I am a beginner in python, Could someone help me how to make a contour using python. For example i have 4 days data below :

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

How to make a contour, if i would like makes x axis=day number, y axis=height and z=temp data. Thank you very much
 
Ranch Hand
Posts: 44
1
Python VI Editor Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you said that you wanted to make a contour, did you mean a contour plot or graph?  If so, perhaps this can be solved using the pandas and matplotlib libraries.  When I did search using those two library names, I found numerous sites that will teach someone how to use those libraries to load data and create graphs from it.

HTH,
Travis
 
Dodi Ardiansyah
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear travis,
I mean i want to make a contour plot using python, Could you give me some suggestion how to make it?
 
Travis Risner
Ranch Hand
Posts: 44
1
Python VI Editor Postgres Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dodi,

Did you try searching on "python pandas matplotlib" yet?  Are you using modern python (version 3) or jython/legacypython?  The link for pandas documentation for modern python starts at https://pandas.pydata.org/pandas-docs/stable/.  I took a closer look at matplotlib and discovered that it is only good for 2D graphs.  This link https://stackoverflow.com/questions/36589521/how-to-surface-plot-3d-plot-from-dataframe shows a hint about how to create a 3D graph.

If you are forced to use Jython/legacy Python. we will have to look further for a solution or find a way to graft a modern python solution back into your current framework.

HTH,
Travis
 
Dodi Ardiansyah
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Travis,

I have been searching on the web there is so many example, but i am still confused because i am a beginner. I have tried my script below :

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()

A contour has not showed. I don't know in where part i have wrong because nothing error warning from my script above. Perhaps you can help me travis.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic