Make graph skip certain amount of x value Python

20 Views Asked by At

I am trying to write a code to make Python skip certain x value on a graph without compressing the x values in front of it.

import matplotlib.pyplot as plt
import numpy as np

#de y waarde vragen en convergeren van string naar float
x1 = float(input("Voer geluidssterkte op afstand 1 in:"))

x2 = float(input("Voer geluidssterkte op afstand 2 in:"))

x3 = float(input("Voer geluidssterkte op afstand 3 in:"))

x4 = float(input("Voer geluidssterkte op afstand 4 in:"))


#x-as waarde
x = [5 , 10, 15, 300]
#y-as waarde
y = [x1, x2 ,x3, x4]


#grafiek plotten
plt.plot(x, y, color = 'blue', linewidth = 1, marker = 'o', markerfacecolor = 'red', markersize = 5)

#Python forceren om alleen de nodige x waarden te weergeven
plt.xticks(np.arange(5, 300, 5))

#x-as limiet opstellen
plt.xlim(0, 300)


#naam x-as
plt.xlabel('afstand (cm)')
#naam y-as
plt.ylabel('geluidssterkte (dB)')

#naam van de grafiek
plt.title('geluidssterkte')


plt.show()

enter image description here

I want to make it appear like this but instead of 20 400 on the right side of the x-axis.

import matplotlib.pyplot as plt
import numpy as np

#de y waarde vragen en convergeren van string naar float
x1 = 123
x2 = 432
x3 = 424
x4 = 243

#x-as waarde
x = [5, 10, 15, 20, 300]
#y-as waarde
y = [x1, x2, x3, x4]

#grafiek plotten
fig, ax1 = plt.subplots()

ax1.plot((x[:4]), y, color = 'blue', linewidth = 1, marker = 'o', markerfacecolor = 'red', markersize = 5)
ax1.set_xlabel('afstand (cm)')
ax1.set_ylabel('geluidssterkte (dB)')

#extra x-as toevoegen voor x = 
ax2 = ax1.twiny()
ax2.set_xlim(ax1.get_xlim())
ax2.set_xticks([20, 300])
ax2.set_xticklabels(['20', '300'])
ax2.set_xlabel('Afstand (cm)')

# Naam van de grafiek
plt.title('Geluidssterkte')

plt.show()

enter image description here

Does anyone know how to do it?

1

There are 1 best solutions below

0
J_H On

Use photoshop. Or its moral equivalent, where you ask the pillow PIL library to delete a vertical swath from a “finished” output chart.PNG