user1821176
user1821176

Reputation: 1191

Showing more ticks labels on log plot

Suppose I have a log plot shown below enter image description here

I'm trying to display more numbers on ticks for both my y and x axis. The ticks should be something as shown in this plot showing more of the exponents for each log. enter image description here

I tried using tick_params but it does not work on my code:

plt.figure(figsize=(20,10))
plt.scatter(y_hat_rdg, y_test, s=30, c='r', marker='+', zorder=10, label=None)
plt.xlabel("Predicted Prices ($)", size=20)
plt.ylabel("Actual Prices ($)", size=20)
plt.title("Actual Prices vs. Predicted Prices", size=25)
plt.xscale('log')
plt.yscale('log')
plt.xticks(fontsize=25)
plt.yticks(fontsize=25)
plt.tick_params( which='both') 
plt.plot([np.min(y_hat), np.max(y_hat)], [np.min(y_hat), np.max(y_hat)], label='RidgeCV Prediction Model')
plt.legend(loc=2, prop={'size': 20})
plt.show()

Upvotes: 0

Views: 59

Answers (1)

meW
meW

Reputation: 3967

One of the way using log10 of linspace:

plt.figure(figsize=(10,5))
plt.plot(np.arange(10000, 500000), np.arange(10000, 500000))
plt.yscale('log')
plt.xscale('log')
plt.xticks(np.linspace(10000, 500000, 10), np.round(np.log10(np.linspace(10000, 500000, 10)),2))
plt.yticks(np.linspace(10000, 500000, 10), np.round(np.log10(np.linspace(10000, 500000, 10)),2))
plt.tight_layout()

Example

Upvotes: 1

Related Questions