0

I need to build a graph from a group of files. My script below and output.

import sys
import matplotlib.pyplot as plt
import matplotlib.image as img
import pandas as pd
import numpy as np
import glob

df=ReadMultPRYFiles(f"/data/beegfs/projects/XOMG2201-FLD/databases/orient/RL53744.00/RL*RP_15*")
# Define variables
X = df['x num']
Y = df['y num']
z = df['value']

# Plot the x, y, and z coordinates as a scatter plot with color representing z
plt.scatter(X, Y, c=z, cmap='rainbow', s=20, marker = 's',zorder=10)

# Y ticks frequency
plt.yticks(np.arange(min(Y), max(Y), 10))

# Add labels to the x and y axes
plt.xlabel('REC_X')
plt.ylabel('REC_Y')
# display
plt.show()

enter image description here

All good but I would like to see on Y label only the values I actually have, from 15264 to 15808, without interpolation or values outside the range. The interval may vary, unfortunately.

esse_emme
  • 13
  • 5

2 Answers2

0

to have yticks only for the existing y values you can change the following line

plt.yticks(np.arange(min(Y), max(Y), 10))

to the

plt.yticks(Y.sort_values().tolist())

Performance Improvements

The above answer seems a little bit inefficient. We only need unique values in the Y axis so the following piece of code could do the trick but in a more efficient way.

plt.yticks(np.sort(Y.unique()).tolist())

We are taking advantage of NumPy instead of pandas. and we perform the sorting/converting to list only on the unique values

0
plt.yticks(np.unique(Y))

As suggested by JohanC works well and quickly.

esse_emme
  • 13
  • 5