0

(Asking same question again as it was marked duplicate but I couldn't resolve it with suggested solution) I am new to python and trying to plot a contour graph. I got the expected results but want to remove levels=0 from my graph. Please help. Here's my code:

import numpy as np
from scipy.interpolate import Rbf
import matplotlib.pyplot as plt

df = (
    spark.read.csv('/home/Downloads/test1.csv', header=True, inferSchema=False, sep='|')
    .withColumn('x', expr("cast(Width as double)"))
    .withColumn('y', expr("cast(Length as double)"))
    .withColumn('z', expr("cast(Depth as double)"))
)

data = df.toPandas()
# Interpolate these onto a regular grid
xi, yi = np.meshgrid(data.x, data.y)
func = Rbf(data.x, data.y, data.z, function='linear')
zi = func(xi, yi)
# plt.contour(xi, np.flip(yi), zi)
qwe = plt.contour(xi, yi, zi)
plt.colorbar()

Sample data

Here's the picture of my current output.(yellow lines are the one that i want to remove) Plot pic

jaggi
  • 1
  • 2
  • 1
    imports are missing, name 'data' is not defined, please provide mre https://stackoverflow.com/help/minimal-reproducible-example – pippo1980 Aug 15 '21 at 17:43
  • If you read the documentation, you can see that contour has a parameter levels – Stefan Aug 15 '21 at 18:18
  • @Stefan Yes, and i want to remove levels = 0. – jaggi Aug 16 '21 at 13:32
  • @pippo1980 I have added the sample data in google drive and shared the link, also updated the code to complete code. Thanks – jaggi Aug 16 '21 at 15:54

1 Answers1

0

The following worked for me.

qwe = plt.contour(xi, yi, zi).collections[-1].remove()
plt.colorbar()

Here's the full example How to remove/omit smaller contour lines using matplotlib