示例#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
from mpl_toolkits import axisartist
import json
import os
import sys
import seaborn as sns
from freeplot.base import FreePlot



A = [1., 2., 3.]
B = [2., 3., 4.]
T = ['One', 'Two', 'Three'] * 2
Hue = ['A'] * len(A) + ['B'] * len(B)

data = pd.DataFrame(
    {
        "T": T,
        "val": A + B,
        "category": Hue
    }
)

# shape: 1, 1; figsize: 2.2, 2
fp = FreePlot((1, 1), (2.2, 2), titles=("Bar Demo",), dpi=200)
fp.barplot(x='T', y='val', hue='category', data=data, index=(0, 0), auto_fmt=True)

fp.set(xlabel='X')
fp.set_label('Y', index=(0, 0), axis='y')
fp[0, 0].legend(ncol=2)
# fp.savefig("heatmap_demo.pdf", format="pdf", tight_layout=False)
plt.show()