Ich erstelle ein Diagramm und erhalte das nächste Ergebnis:
Wie kann man diese schlechte Nummerierung und 1e6
höher beheben ?
Warum ist das so?
Ich habe versucht, die Lösung zu verwenden, um die wissenschaftliche Notation in matplotlib.pyplot zu verhindern , aber es hat nicht funktioniert.
Mein Code:
import matplotlib.pyplot as plt
plt.title(f'TOP 10 videos by {choice}')
plt.xlabel('TOP places')
plt.ylabel(f'Number')
labels_top = ['Top10', 'Top9', 'Top8', 'Top7', 'Top6', 'Top5', 'Top4', 'Top3', 'Top2', 'Top1']
y_count = [50235, 90312, 150123, 250000, 290134, 370241, 385153, 768512, 955025, 1255531]
for graph in range(len(y_count[:10])):
plt.bar(labels_top.pop(), y_count.pop())
plt.gca().ticklabel_format(style='plain')
Ich habe diesen Fehler:
Traceback (most recent call last):
File "/home/vitalii/PycharmProjects/mediagroupukraine_test_task/venv/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 3130, in ticklabel_format
axis.major.formatter.set_scientific(is_sci_style)
AttributeError: 'StrCategoryFormatter' object has no attribute 'set_scientific'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "app.py", line 41, in <module>
start()
File "app.py", line 37, in start
app(channel_name, channel_id)
File "app.py", line 27, in app
menu_graphs()
File "app.py", line 25, in menu_graphs
show_statistic_graph(formatted_data_for_graphs, menu_choice)
File "/home/vitalii/PycharmProjects/mediagroupukraine_test_task/graphs.py", line 48, in show_statistic_graph
plt.gca().ticklabel_format(style='plain')
File "/home/vitalii/PycharmProjects/mediagroupukraine_test_task/venv/lib/python3.8/site-packages/matplotlib/axes/_base.py", line 3140, in ticklabel_format
raise AttributeError(
AttributeError: This method only works with the ScalarFormatter
Sie müssen angeben, an matplotlib.axes.Axes.ticklabel_format
welche Achse Sie formatieren möchten, in Ihrem Fall nur y
Achse, also:
plt.gca().ticklabel_format(axis='y', style='plain')
Da Sie keinen axis
Parameter an übergeben ticklabel_format
, wird der Standardwert verwendet, also both
. Auf diese Weise matplotlib
wird versucht, auch mit der style = 'plain'
x-Achse zu formatieren , aber dies ist nicht machbar, also erhalten Sie die AttributeError
.
Dieser Artikel stammt aus dem Internet. Bitte geben Sie beim Nachdruck die Quelle an.
Bei Verstößen wenden Sie sich bitte [email protected] Löschen.
Lass mich ein paar Worte sagen