Issue
I am plotting a graph using pcolormesh
:
fig, ax = plt.subplots()
ax.pcolormesh(Omega_re, Omega_im, brightness, cmap="gray", shading="gouraud")
ax.set_xlabel(r"$Re(\omega)$")
ax.set_ylabel(r"$Im(\omega)$")
ax.set_aspect(1)
fig.show()
where
Omega_re = array([[2. , 2.75, 3.5 , 4.25, 5. ], [2. , 2.75, 3.5 , 4.25, 5. ],
[2. , 2.75, 3.5 , 4.25, 5. ], [2. , 2.75, 3.5 , 4.25, 5. ],
[2. , 2.75, 3.5 , 4.25, 5. ]])
Omega_im = array([[0. , 0. , 0. , 0. , 0. ], [0.0005, 0.0005, 0.0005, 0.0005, 0.0005],
[0.001 , 0.001 , 0.001 , 0.001 , 0.001 ], [0.0015, 0.0015, 0.0015, 0.0015, 0.0015],
[0.002 , 0.002 , 0.002 , 0.002 , 0.002 ]])
brightness = array([[4.05649772, 3.7299948 , 2.61262439, 4.2841897 , 3.40368949],
[4.05649076, 3.72997624, 2.61258381, 4.2841071 , 3.40353591],
[4.05648399, 3.72995772, 2.61254052, 4.28402084, 3.40338229],
[4.05647716, 3.72993901, 2.6124984 , 4.28393373, 3.40322865],
[4.05647025, 3.72992049, 2.61245428, 4.2838476 , 3.40307499]])
But since the x-axis ranges from 0 to 5 and the y-axis ranges from 0 to 0.002, the result appears "flattened.":
Is there a way to rescale the y-axis so that the graph looks visually better? Below is a picture of how it is currently being displayed.
Solution
Replace
ax.set_aspect(1)
with
ax.set_aspect("auto")
or simply remove the line entirely.
set_aspect(1)
(or equivalently set_aspect("equal")
) forces the axes to use the same scaling for x and y. Using set_aspect("auto")
(the default) allows matplotlib to infer a good scaling to fill the plot.
Result
Answered By - Brian61354270
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.