Skip to content

Commit

Permalink
Fix cmap issue between matplotlib and pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Jul 18, 2024
1 parent 507f7dc commit 7731550
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/python/cpuinfo/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from psutil import cpu_count, cpu_percent

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from helpers import plot_cpu
Expand Down Expand Up @@ -120,11 +121,17 @@ def table():
latest = pd.DataFrame(history).transpose().tail(input.table_rows())
if latest.shape[0] == 0:
return latest

# Must set this globally to avoid a compatibility issue between
# matplotlib 3.5.2 and pandas 2.2.0. In newer versions of either,
# you can just call background_gradient(cmap=input.cmap()).
plt.rcParams["image.cmap"] = input.cmap()

return (
latest.style.format(precision=0)
.hide(axis="index")
.set_table_attributes(
'class="dataframe shiny-table table table-borderless font-monospace"'
)
.background_gradient(cmap=input.cmap(), vmin=0, vmax=100)
.background_gradient(cmap=None, vmin=0, vmax=100)
)

0 comments on commit 7731550

Please sign in to comment.