0

I already made the graph below:

i tried to change the scale of x-axis to 10^n with n = -4,-2,-1,0,1: First figure the second graph is made with matlab: Second figure

i've tried with xtics function in python (first figure), but the result isn't how it's supposed to be.

how to change the graph scale in python so that the result will be the same as second figure?

this is the plotting code i've made in python:


...

plt.figure()
plt.subplot(211)
plt.title('Grafik Simpangan dan Kecepatan')
plt.plot(array_1,array_3, 'r')
plt.ylabel('Simpangan (y) meter')
plt.xticks([0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10])
plt.grid()

plt.subplot(212)
plt.plot(array_1,array_2, 'b')
plt.ylabel('Kecepatan (v) m/s')
plt.xlabel('Waktu (s)')
plt.xticks([0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10])
plt.grid()
    
plt.show()
HezTech
  • 29
  • 3
  • You want to set the x-axis to be a logarithmic scale. You can change `plt.plot(array_1, array_3)` to [`plt.semilogx(array_1, arrar_3)`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xscale.html). Or alternatively, you can just call [`plt.xscale('log')`](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xscale.html). – tmdavison Jun 28 '21 at 09:14

1 Answers1

-1

, Can you share the code which you used in matlab????

Alternatively USE matplotlib.pyplot.xlim() AND matplotlib.pyplot.ylim() TO CHANGE THE AXIS SCALES Call matplotlib.pyplot.xlim() and matplotlib.pyplot.ylim() to get the x and y limits of the current axes. Then call matplotlib.pyplot.xlim(new_xmin, new_xmax) and matplotlib.pyplot.ylim(new_ymin, new_ymax) to set the x and y limits to new values, each of which is the original value multiplied by the scale factor.

plt.xlim(xmin * scale_factor, xmax * scale_factor)
plt.ylim(ymin * scale_factor, ymax * scale_factor)
  • thank for your answer. Sorry i can't show the matlab code, because i got the figure from Journal and the authors only show the figure. I have tried your suggestion but the result is still not what i expected. `This is my code` – HezTech Jun 28 '21 at 08:12
  • `...` `` `plt.figure()` `plt.subplot(211)` `plt.title('Grafik Simpangan dan Kecepatan')` `plt.plot(array_1,array_3, 'r')` `plt.ylabel('Simpangan (y) meter')` `plt.xlim(1 * 10**-4, 1 * 10)` `plt.xticks([0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10])` `plt.grid()` `` `plt.subplot(212)` `plt.plot(array_1,array_2, 'b')` `plt.ylabel('Kecepatan (v) m/s')` `plt.xlabel('Waktu (s)')` `plt.grid()` `plt.xticks([0.00001, 0.0001, 0.001, 0.01, 0.1, 1, 10])` `plt.xlim(1 * 10**-4, 1 * 10)` `plt.show()` [link](https://imgur.com/a/aCHzXuW) – HezTech Jun 28 '21 at 08:22
  • [plt.semilogx](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.semilogx.html) can be used to produce a plot with the logarithmic scale on the x-axis. [Here](https://www.geeksforgeeks.org/matplotlib-axes-axes-semilogx-in-python/) are some examples. – bb1 Jun 28 '21 at 08:35