Fill matplotlib contour plot


Joan Carl Montero Jimenez

With the following code, I get the following contour plot:

fig, ax = plt.subplots()
x = np.arange(431)
y = np.arange(225)
Y, X = np.meshgrid(y, x)
values = df["Appearance_percentage"].values
values2d = np.reshape(values, (431, 225))
ax.set_ylim(225, 0)

plt.style.use('seaborn-white')
ax.set_title('Mapa contour de probabilitat de trobar núvols')
plt.contour(X, Y, values2d, 30, cmap='RdGy')
plt.colorbar()
plt.savefig("contourmap.png")

Contour map

I would like to know if it is possible to fill the area between the lines so that there is no white space in the colorbar and the map is more attractive.

I try to do this df["Appearance_percentage_contourmap"] = round(df["Appearance_percentage"])and values = df["Appearance_percentage_contourmap"].valuesstill get the same map with a lot of white areas.

Maximum power

Just replace plt.contourwith plt.contourf, the "f" at the end means "fill".

Here is an example:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(100)
y = np.arange(100)
Y, X = np.meshgrid(y, x)
values = np.outer(x, y)

fig, ax = plt.subplots()
plt.contourf(X, Y, values, 30, cmap='RdGy')
plt.colorbar()

Fill contour plot.

You may also want to emphasize contour lines:

x = np.arange(100)
y = np.arange(100)
Y, X = np.meshgrid(y, x)
values = np.outer(x, y)

fig, ax = plt.subplots()
c1 = plt.contourf(X, Y, values, 30, cmap='RdGy')
c2 = plt.contour(X, Y, values, 30, cmap='Greys')
plt.colorbar(c1)

Fills the contour plot with contour lines.

Related


Fill matplotlib contour plot

Joan Carl Montero Jimenez With the following code, I get the following contour plot: fig, ax = plt.subplots() x = np.arange(431) y = np.arange(225) Y, X = np.meshgrid(y, x) values = df["Appearance_percentage"].values values2d = np.reshape(values, (431, 225)) a

Fill matplotlib contour plot

Joan Carl Montero Jimenez With the following code, I get the following contour plot: fig, ax = plt.subplots() x = np.arange(431) y = np.arange(225) Y, X = np.meshgrid(y, x) values = df["Appearance_percentage"].values values2d = np.reshape(values, (431, 225)) a

Fill matplotlib contour plot

Joan Carl Montero Jimenez With the following code, I get the following contour plot: fig, ax = plt.subplots() x = np.arange(431) y = np.arange(225) Y, X = np.meshgrid(y, x) values = df["Appearance_percentage"].values values2d = np.reshape(values, (431, 225)) a

Fill matplotlib contour plot

Joan Carl Montero Jimenez With the following code, I get the following contour plot: fig, ax = plt.subplots() x = np.arange(431) y = np.arange(225) Y, X = np.meshgrid(y, x) values = df["Appearance_percentage"].values values2d = np.reshape(values, (431, 225)) a

Fill matplotlib contour plot

Joan Carl Montero Jimenez With the following code, I get the following contour plot: fig, ax = plt.subplots() x = np.arange(431) y = np.arange(225) Y, X = np.meshgrid(y, x) values = df["Appearance_percentage"].values values2d = np.reshape(values, (431, 225)) a

legend fill contour plot

pier I'm trying to create a contour plot using fill.contour and I want to change the size of the legend title and labels as well as the size of the legend itself. I already have code for the data which is very similar to the volcano example (easier to reproduc

legend fill contour plot

pier I'm trying to create a contour plot using fill.contour and I want to change the size of the legend title and labels as well as the size of the legend itself. I already have code for the data which is very similar to the volcano example (easier to reproduc

Python matplotlib contour plot

Jie Dejuan I have a question about matplotlib and contourf. I am using the latest version of matplotlib with python3.7. Basically I have to matrix I want to plot on the same contour plot but with different colormaps. An important aspect is that, for example, i

Python matplotlib contour plot

Jie Dejuan I have a question about matplotlib and contourf. I am using the latest version of matplotlib with python3.7. Basically I have to matrix I want to plot on the same contour plot but with different colormaps. An important aspect is that, for example, i

Matlab: Fill contour plot with contour lines

Dave I am trying to create a filled contour plot from an image in MATLAB. However, the command imcontourdoesn't seem to have an option for filling the outline. If used contourf, it will draw all outlines black. Since the image has many outlines, it appears alm

Matlab: Fill contour plot with contour lines

Dave I am trying to create a filled contour plot from an image in MATLAB. However, the command imcontourdoesn't seem to have an option for filling the outline. If used contourf, it will draw all outlines black. Since the image has many outlines, it appears alm

Matlab: Fill contour plot with contour lines

Dave I am trying to create a filled contour plot from an image in MATLAB. However, the command imcontourdoesn't seem to have an option for filling the outline. If used contourf, it will draw all outlines black. Since the image has many outlines, it appears alm

How to smooth matplotlib contour plot?

angle I have a numpy array of the following shape: (33, 10). When I draw contours, I get ugly images like this: And contour()there doesn't seem to be any argument for smoothing or some kind of interpolation function. I somehow expected that tools that provide

ValueError for matplotlib contour plot in Python

Cam K I am getting "ValueError: Array element is set with sequence" at runtime. I've tried to turn everything into a numpy array, to no avail. import matplotlib import numpy as np from matplotlib import pyplot X=np.array([ np.array([1,2,3,4,5,6,7]), n

How to smooth matplotlib contour plot?

angle I have a numpy array of the following shape: (33, 10). When I draw contours, I get ugly images like this: And contour()there doesn't seem to be any argument for smoothing or some kind of interpolation function. I somehow expected that tools that provide

ValueError for matplotlib contour plot in Python

Cam K I am getting "ValueError: Array element is set with sequence" at runtime. I've tried to turn everything into a numpy array, to no avail. import matplotlib import numpy as np from matplotlib import pyplot X=np.array([ np.array([1,2,3,4,5,6,7]), n

Matplotlib Contour Plot with Curve Conditions

physicist Suppose I want to draw the outline of z=0where z=(19*y^3-6*x*y-1). I can use the following code: x = np.linspace(-2,2,1000) y = np.linspace(-1,1,1000) X,Y = np.meshgrid(x,y) z = (19)*Y**3-6*X*Y-1 plt.figure() plt.contour(z,0) plt.show() Now I want t

matplotlib contour plot in given range

bob I need to draw an ellipse as shown in the image below. The code is from a tutorial. But I need to draw an ellipse in the range X: [-10, -10] and Y: [-2, -2]. How should I modify my code? fig = plt.figure() x = linspace(0, 10, 51) y = linspace(0, 8, 41) (X,

matplotlib contour plot in given range

bob I need to draw an ellipse as shown in the image below. The code is from a tutorial. But I need to draw an ellipse in the range X: [-10, -10] and Y: [-2, -2]. How should I modify my code? fig = plt.figure() x = linspace(0, 10, 51) y = linspace(0, 8, 41) (X,

excel vs matplotlib contour plot

Environmental friendly I'm trying to reproduce an Excel chart in matplotlib, but the matplotlib version appears to be truncated. The excel version draws the entire ellipse, while the matplolib version doesn't. The excel graph is only generated using the insert

How to smooth matplotlib contour plot?

angle I have a numpy array of the following shape: (33, 10). When I draw contours, I get ugly images like this: And contour()there doesn't seem to be any argument for smoothing or some kind of interpolation function. I somehow expected that tools that provide

excel vs matplotlib contour plot

Environmental friendly I'm trying to reproduce an Excel chart in matplotlib, but the matplotlib version appears to be truncated. The excel version draws the entire ellipse, while the matplolib version doesn't. The excel graph is only generated using the insert

matplotlib contour plot in given range

bob I need to draw an ellipse as shown in the image below. The code is from a tutorial. But I need to draw an ellipse in the range X: [-10, -10] and Y: [-2, -2]. How should I modify my code? fig = plt.figure() x = linspace(0, 10, 51) y = linspace(0, 8, 41) (X,

Matplotlib: Plot scatter to foreground on top of contour plot

Mike: Does anyone know a way to bring a scatter plot to the foreground in matplotlib? I have to show a scatter plot above the contour lines, but by default it's drawn below... Thanks in advance! sodd : You can manually choose the order in which the different p

Matplotlib: Plot scatter to foreground on top of contour plot

Mike: Does anyone know a way to bring a scatter plot to the foreground in matplotlib? I have to show a scatter plot above the contour lines, but by default it's drawn below... Thanks in advance! sodd : You can manually choose the order in which the different p

Matplotlib: Plot scatter to foreground on top of contour plot

Mike: Does anyone know a way to bring a scatter plot to the foreground in matplotlib? I have to show a scatter plot above the contour lines, but by default it's drawn below... Thanks in advance! sodd : You can manually choose the order in which the different p

Matplotlib: Plot scatter to foreground on top of contour plot

Mike: Does anyone know a way to bring a scatter plot to the foreground in matplotlib? I have to show a scatter plot above the contour lines, but by default it's drawn below... Thanks in advance! sodd : You can manually choose the order in which the different p

Matplotlib: Plot scatter to foreground on top of contour plot

Mike: Does anyone know a way to bring a scatter plot to the foreground in matplotlib? I have to show a scatter plot above the contour lines, but by default it's drawn below... Thanks in advance! sodd : You can manually choose the order in which the different p

Matplotlib: Plot scatter to foreground on top of contour plot

Mike: Does anyone know a way to bring a scatter plot to the foreground in matplotlib? I have to show a scatter plot above the contour lines, but by default it's drawn below... Thanks in advance! sodd : You can manually choose the order in which the different p