Python Forum
Matplotlib contour no data coordinates
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matplotlib contour no data coordinates
#1
I have problem with Matplotlib contour graph. I have graph size (100x100). All "importance" values of CSV which are >0 should be red. Every value <0 should be blue.

My question is, if is possible to have places with no data (no coordinates in CSV) in white color. Now it's couting some average color from nearby points.

This is situation which I have right now:
[Image: QWqMv.png]

This is data visualized by points:
[Image: 0kvoV.png]

This type of graph that I need:
[Image: wGUNP.png]

Is possible to get similar graph by using Contour?

This is my code:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as ml
import pandas as pd

csv_filename = 'data.csv'
df = pd.read_csv(csv_filename)

data = [df.x_pos, df.y_pos]
x = df.x_pos
y = df.y_pos
z = df.importance


ny, nx = 1000, 1000
xmin, xmax = 0, 100
ymin, ymax = 0, 100

xi = np.linspace(xmin, xmax, nx)
yi = np.linspace(ymin, ymax, ny)


zi = ml.griddata(x, y, z, xi, yi, interp='linear')

plt.contour(xi, yi, zi, 1, linewidths = 0, colors = 'k')
plt.pcolormesh(xi, yi, zi, vmin=-1, vmax=1, cmap = plt.get_cmap('bwr'))

#plt.scatter(x, y, marker = 'o', c = z, s = 10, vmin=-1, vmax=1, cmap = plt.get_cmap('bwr'))
plt.colorbar() 

plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)
plt.show()
This is CSV data example:
x_pos,y_pos,importance
32,-48,0.87487145766094
32,52,0.43743572883047
32,68,1.127350663193
Full CSV data is here: https://pastebin.com/mYS6LSyG
Reply
#2
bump pls
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Vertex(Contour) to mesh conversion JorgeRdz 1 674 Feb-06-2023, 02:00 AM
Last Post: Larz60+
  Error 'Contour' not Defined DaveG 3 2,283 Mar-13-2022, 03:29 AM
Last Post: deanhystad
  Trying to get base64Encoded Matplotlib Data Morkus 0 1,402 Jun-10-2021, 06:58 PM
Last Post: Morkus
  blank graph with matplotlib from a csv file / data type issue arsentievalex 0 1,911 Apr-06-2021, 10:08 AM
Last Post: arsentievalex
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,161 Mar-11-2021, 10:52 AM
Last Post: buran
  How to make a contour plot in python(matplotli) Ardi 0 1,863 Nov-28-2019, 04:45 AM
Last Post: Ardi
  Matplotlib Hovering Event displaying (x, y) data RawlinsCross 0 6,086 Oct-18-2019, 06:13 PM
Last Post: RawlinsCross
  Contour Sort Explain Killing_Machine 0 1,882 Aug-18-2018, 10:41 AM
Last Post: Killing_Machine

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020