Reputation: 13
from matplotlib import pyplot as plt
import numpy as np
x = np.linspace(448312,497812,100)
y = np.linspace(7188379,7986879,1598)
z = np.random.rand(100,1598)
interp_method = "sinc"
fig, axs = plt.subplots()
axs.imshow(z, interpolation=interp_method, cmap='viridis', extent= (x[0], x[-1], y[0], y[-1]))
axs.set_title(str(interp_method))
plt.show()
# the image is on https://imgur.com/ZYIkqAw
The previous code produces a heatmap that isn't quite readable, is there a way to "expand" the x axis without creating interpolated values? I tried several approaches but all failed I changed figsize (failed), i changed the axes with:
axs=plt.axes([.65, .6, 10, 10], facecolor='k',aspect='equal')
but it ultimately is impossible to widen the heatmap enough to make it clearer. I don't really want to create empty values in the x axis and use a plot to interpolate them. Is there a way to "zoom" in to x axis and make the plot seem square?
I checked the following links thoroughly but i couldn't get something that could've helped:
How to change spacing between ticks in matplotlib?
How do I add space between the ticklabels and the axes in matplotlib?
https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.set_aspect.html
Thanks in advance everyone :) Any help is much appreciated
Upvotes: 1
Views: 755
Reputation: 1767
If you want a square plot:
axs.imshow(z, interpolation=interp_method, cmap='viridis', extent= (x[0], x[-1], y[0], y[-1]), aspect=“auto”)
Note it is the same code as yours, just added the aspect=“auto”
argument to imshow()
.
Here's the image: https://i.sstatic.net/U2GFD.jpg
Upvotes: 1