 # I don't know how to describe my problem 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!

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):
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))

for mid, lab in zip(mid_points, labels):
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.text(0, -0.05, title, horizontalalignment='center', \
verticalalignment='center', fontsize=22, fontweight='bold')

pos = mid_points[abs(arrow - N)]

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]`.

2 Likes

It’s fixed, thanks a lot!