Back
Close

Computing with Data

elgeish
33.1K views

Contour Plots

The most convenient way to graph a two-dimensional function f(x, y) is graphing its equal height contours:

x_grid = seq(-1, 1, length.out = 100)
y_grid = x_grid
# Create a dataframe containing all possible combinations of (x, y)
df = expand.grid(x_grid, y_grid)
dim(df) # number of rows is 100 x 100 - one for each combination
names(df) = c("x", "y") # modify column names for better labeling
df$z = df$x ^ 2 + df$y ^ 2
head(df)
ggplot(df, aes(x = x, y = y, z = z)) + stat_contour()
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants