I have numpy array with this shape: (33,10). When I plot contour I get ugly image like this:
while contour()
doesn't seem to have any argument about smoothing or some sort of interpolation feature.
I somehow expected that tool which offers contour plot should offer smoothing too.
Is there straight forward way to do it in MPL?
Choose the "smoothness" of the new plot via the parameter newpoints . A 3D-surf plot would be more suitable for very smooth color-shading. Just rotate it to a top-down view.
Contour plots (sometimes called Level Plots) are a way to show a three-dimensional surface on a two-dimensional plane. It graphs two predictor variables X Y on the y-axis and a response variable Z as contours. These contours are sometimes called the z-slices or the iso-response values.
Color maps on contour plots The default color scheme of Matplotlib contour and filled contour plots can be modified. A general way to modify the color scheme is to call Matplotlib's plt. get_cmap() function that outputs a color map object. There are many different colormaps available to apply to contour plots.
As others have already pointed out, you need to interpolate your data.
There are a number of different ways to do this, but for starters, consider scipy.ndimage.zoom
.
As a quick exmaple:
import numpy as np import scipy.ndimage import matplotlib.pyplot as plt data = np.loadtxt('data.txt') # Resample your data grid by a factor of 3 using cubic spline interpolation. data = scipy.ndimage.zoom(data, 3) plt.contour(data) plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With