如何制作可视化草图? R或Python中有什么程序或包?

How to make visualization sketches? What program or package in R or Pyhon is there?

几年前发布了这个命运情节。现在我需要创建类似的草图, 有谁知道这些是如何创建的?什么技术最适合制造类似的东西?

这张图最初张贴在这里...

How to use 'facet' to create multiple density plot in GGPLOT

谢谢!

您可以使用 ggplot facets

library("tidyverse")
data = iris %>% gather(key, value, -Species)
data %>% 
   ggplot(aes(x = value, color = Species)) + 
   geom_density() + 
   facet_wrap(key ~ .)

python xkcd() 中有这个 matplotlib 方法,它旨在使绘图看起来像 sckechy。它会给你的任何 matplotlib 图带来那种手工制作的外观。

我不确定你是否要求这个,但无论如何我觉得很有创意:

# Load libraries
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats

# Set style and an auxiliar list
plt.style.use('bmh')
figs = []

# Initialise figure and let no space between subplots 
f = plt.figure(figsize = (15,15))
f.subplots_adjust(hspace=0, wspace=0)

# Set the main plot axis labels as text boxes
f.text(0.5, 0.04, r'log2(u)', ha='center', va='center', fontsize=50, color = 'firebrick')
f.text(0.06, 0.5, 'Density', ha='center', va='center', rotation='vertical', fontsize=50, color = 'firebrick')

#Add some magic
plt.xkcd(scale=5, length=800)

# For each plot
for i in range(4):

    plt.subplot(2,2,i+1)
    # Remove internal axis labels
    if i in [0,1]:
        plt.xticks([], [])
    if i in [1,3]:
        plt.yticks([], [])    

    # Set figure captions   
    difs = [r'$W_c - W_n$', r'$X_c - X_n$', r'$Y_c - Y_n$',r'$Z_c - Z_n$']    
    plt.text(0,0,difs[i], fontsize=30, ha = 'center',bbox = dict(facecolor='white', alpha=0.6, edgecolor='red'))

    # generate a couple of gaussians to plot with random mu and sigma
    x = np.linspace(-5,5, 100)
    sigma = (np.random.rand()+0.5)
    mu1 = np.random.choice([-2,-1,0,1,2])
    mu2 = mu1
    while mu2 == mu1:
        mu1 = np.random.choice([-2,-1,0,1,2])
    x1 = stats.norm(mu1,sigma).pdf(x)
    x2 = stats.norm(mu2,sigma).pdf(x)

    # We generate the fill plots 
    a = plt.fill(x, x1, alpha = 0.3,label='C')
    b = plt.fill(x, x2, alpha = 0.3,label='N', color = 'coral')
    plt.xlim(-6,6)
    #get the figures to use them for the legend
    figs.extend([a,b])


# Set the main legend
L=f.legend(figs[0:2],loc='upper center',
          ncol=2, fancybox=True, shadow=True, fontsize = 40)

L.get_texts()[0].set_text('CANCER (c)')
L.get_texts()[1].set_text('NORMAL (n)')

plt.show()