Data Visualizations in Python and R
Python:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Simple Line Plot')
plt.show()
2. Seaborn:
import seaborn as sns
tips = sns.load_dataset('tips')
sns.barplot(x='day', y='total_bill', data=tips)
3. Plotly:
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species")
fig.show()
4. Bokeh:
from bokeh.plotting import figure, output_file, show
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
output_file("line_plot.html")
p = figure(title="Simple Line Plot", x_axis_label='X-axis', y_axis_label='Y-axis')
p.line(x, y)
show(p)
***************************************************************************
R:
library(ggplot2)
data <- data.frame(x = c(1, 2, 3, 4, 5), y = c(2, 4, 6, 8, 10))
ggplot(data, aes(x = x, y = y)) + geom_line() +
?xlab("X-axis") + ylab("Y-axis") +
?ggtitle("Simple Line Plot")
2. lattice:
library(lattice)
data <- data.frame(x = c(1, 2, 3, 4, 5), y = c(2, 4, 6, 8, 10))
xyplot(y ~ x, data = data, type = "b",
????xlab = "X-axis", ylab = "Y-axis",
????main = "Simple Line Plot")
3. plotly:
library(plotly)
data <- iris
fig <- plot_ly(data, x = ~Petal.Width, y = ~Petal.Length, color = ~Species, mode = "markers")
fig
4. ggvis:
library(ggvis)
data <- data.frame(x = c(1, 2, 3, 4, 5), y = c(2, 4, 6, 8, 10))
data %>% ggvis(~x, ~y) %>% layer_lines() %>%
?add_axis("x", title = "X-axis") %>%
?add_axis("y", title = "Y-axis") %>%
?set_options(width = 500, height = 300)