示例#1
0
"""
heatmap demo
"""

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from freeplot.base import FreePlot

titles = ("S", "h", "a", "n")
row_labels = ('c', 'u', 't', 'e')
col_labels = ('l', 'r', 'i', 'g')

# shape: 1, 4; figsize: 9, 2
fp = FreePlot((1, 4), (9, 2), titles=titles, dpi=100, sharey=True)

for title in titles:
    data = np.random.rand(4, 4)
    df = pd.DataFrame(data, index=col_labels, columns=row_labels)
    fp.heatmap(df,
               index=title,
               annot=True,
               fmt=".4f",
               cbar=False,
               linewidth=0.5)

fp.set(Xlabel="X")
fp.set_label('Y', index=(0, 0), axis='y')
fp.savefig("heatmap_demo.pdf", format="pdf", tight_layout=False)
# plt.show()
示例#2
0
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from freeplot.base import FreePlot

titles = ("S", "h", "a", "n")
labels = ("sin", "cos", "x")
fp = FreePlot((1, 4), (9.5, 2), titles=titles, dpi=100, sharey=True)

nums = 20
x = np.linspace(-10, 10, nums)
y1 = np.sin(x)
y2 = np.cos(x)
y3 = x
ys = (y1, y2, y3)

for title in titles:
    for i, y in enumerate(ys):
        y = y + np.random.randn(nums)
        fp.lineplot(x, y, index=title, label=labels[i])

fp.set_title(y=1.)
fp.set_label("y", axis='y')
fp.set(Xlabel="x")
fp[0, 0].legend()
# fp.savefig("line_demo.pdf", format="pdf", tight_layout=False)
plt.show()
示例#3
0
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from freeplot.base import FreePlot
from scipy.stats import multivariate_normal

normal = multivariate_normal
titles = ("S", "h", "a", "n")
labels = ("sin", "cos", "x")

# shape: 1, 4; figsize: 9.5, 2
fp = FreePlot((1, 4), (9.5, 2), titles=titles, dpi=100, sharey=True)

nums = 100
means = ((0, 0), (5, 5), (-5, -5))

cov = (2, 1, 1)

for title in titles:
    for i, mean in enumerate(means):
        data = normal.rvs(mean, cov[i], size=nums)
        fp.scatterplot(data[:, 0], data[:, 1], index=title, label=labels[i])

fp.set_title(y=1.)
fp.set_label("Y", index=(0, 0), axis='y')
fp.set_label("X", index=None, axis='x')
fp[0, 0].legend()
# fp.savefig("scatter_demo.pdf", format="pdf", tight_layout=False)
plt.show()