
Hello everyone! I don’t know how to explain this problem 
I created a gauge chart by using matplotlib; but I don’t want to see this drop down text above the chart. How do I disable it?

Hello everyone! I don’t know how to explain this problem 
I created a gauge chart by using matplotlib; but I don’t want to see this drop down text above the chart. How do I disable it?
hi @baligoyem, Welcome to the community!
Could you please share your code. This makes helping you easier.
Thanks!
hi @maarten-betman, thanks for replying! Here is my code for creating a gauge chart:
import matplotlib.pyplot as plt
import streamlit as st
import pandas as pd
import numpy as np
from matplotlib import cm
from matplotlib.patches import Circle, Wedge, Rectangle
def degree_range(n):
start = np.linspace(0, 180, n + 1, endpoint=True)[0:-1]
end = np.linspace(0, 180, n + 1, endpoint=True)[1::]
mid_points = start + ((end - start) / 2.)
return np.c_[start, end], mid_points
def rot_text(ang):
rotation = np.degrees(np.radians(ang) * np.pi / np.pi - np.radians(90))
return rotation
def gauge(labels=['LOW', 'MEDIUM', 'HIGH', 'VERY HIGH', 'EXTREME'], \
colors='jet_r', arrow=1, title='', fname=False):
N = len(labels)
if arrow > N:
raise Exception("\n\nThe category ({}) is greated than \
the length\nof the labels ({})".format(arrow, N))
if isinstance(colors, str):
cmap = cm.get_cmap(colors, N)
cmap = cmap(np.arange(N))
colors = cmap[::-1, :].tolist()
if isinstance(colors, list):
if len(colors) == N:
colors = colors[::-1]
else:
raise Exception("\n\nnumber of colors {} not equal \
to number of categories{}\n".format(len(colors), N))
fig, ax = plt.subplots()
ang_range, mid_points = degree_range(N)
labels = labels[::-1]
patches = []
for ang, c in zip(ang_range, colors):
# sectors
patches.append(Wedge((0.,0.), .4, *ang, facecolor='w', lw=2))
# arcs
patches.append(Wedge((0., 0.), .4, *ang, width=0.10, facecolor=c, lw=2, alpha=0.5))
[ax.add_patch(p) for p in patches]
for mid, lab in zip(mid_points, labels):
ax.text(0.35 * np.cos(np.radians(mid)), 0.35 * np.sin(np.radians(mid)), lab, \
horizontalalignment='center', verticalalignment='center', fontsize=14, \
fontweight='bold', rotation=rot_text(mid))
r = Rectangle((-0.4, -0.1), 0.8, 0.1, facecolor='w', lw=2)
ax.add_patch(r)
ax.text(0, -0.05, title, horizontalalignment='center', \
verticalalignment='center', fontsize=22, fontweight='bold')
pos = mid_points[abs(arrow - N)]
ax.arrow(0, 0, 0.225 * np.cos(np.radians(pos)), 0.225 * np.sin(np.radians(pos)), \
width=0.04, head_width=0.09, head_length=0.1, fc='k', ec='k')
ax.add_patch(Circle((0, 0), radius=0.02, facecolor='k'))
ax.add_patch(Circle((0, 0), radius=0.01, facecolor='w', zorder=11))
plt.title("DQ Score", fontsize = 20)
ax.set_frame_on(False)
ax.axes.set_xticks([])
ax.axes.set_yticks([])
ax.axis('equal')
plt.tight_layout()
if fname:
fig.savefig(fname, dpi=200)
gauge(labels=['VERY LOW', 'LOW', 'MEDIUM', 'HIGH'], \
colors=["#1b0203", "#ED1C24", '#FFCC00', '#007A00'], arrow=2, title="something here")
st.pyplot()
Hi @baligoyem,
I think it’s due to this list comprehension: [ax.add_patch(p) for p in patches].
Since you’re adding patches to ax you don’t have to store it under a variable, but when adding a patch matplotlib always return the patch object. That’s why streamlit is showing a list of patch objects.
Fix would be to store it under a variable, foo = [ax.add_patch(p) for p in patches].
Hi @maarten-betman,
It’s fixed, thanks a lot!