Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

numpy.ndarray object is not callable when trying to change x-Ticks

I am currently working on a university project where I want to plot sentiment scores over a period of time. I’ve attached a picture of said scatterplot. I now want to change the xticks, the xtick labels and the title. However, when trying to change the x-ticks to the quintils of the dates, i get the error "’numpy.ndarray’ object is not callable.

My current Scatterplot

I want the xticks to reflext the min, max, 25%, 50% and 75% quntils of the dates. Since the dates are formatted as yyyymmdd, just calculating the quintils wont work but at this point I have really lost focus on how to solve the problem. Same goes for the changing of the title, though that seems more straight forward.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My code is:

import seaborn as sns

import matplotlib.pyplot as plt

import scipy.stats as stats

# Korrelation überprpfen

correlation, p_value = stats.pearsonr(df_tagesspiegel_final['Datum'], df_tagesspiegel_final['compound'])

print(correlation)

print(p_value)

# Scatterplot erstellen

sns.scatterplot(x='Datum', y = 'compound', data=df_tagesspiegel_final)

#Quintile als xticks speichern

xticks = [df_tagesspiegel_final['Datum'].min(), df_tagesspiegel_final['Datum'].quantile(0.25), df_tagesspiegel_final['Datum'].quantile(0.5), df_tagesspiegel_final['Datum'].quantile(0.75), df_tagesspiegel_final['Datum'].max()]

plt.xticks(ticks=xticks)

plt.set_title('Korrelation von Datum und compound')

plt.set_xlabel('Datum')

plt.set_ylabel('compound')

fig.show()

~~~

I tried updating matplotlib, changing plt.xticks(ticks=xticks) to plt.xticks(ticks=None). Nothing worked. I only get the error: ‘numpy.ndarray’ object is not callable.

I expect the xticks to change in any way really, though I am sure that calculating the quintils of dates is not the right way to go about it.

EDIT: I’ve found the solution for the title problem: I used .set_title instead of title.

>Solution :

Replace

plt.xticks(ticks=xticks)

plt.set_title('Korrelation von Datum und compound')

plt.set_xlabel('Datum')

plt.set_ylabel('compound')

by

plt.gca().set(xticks=xticks, xlabel='Datum', ylabel='compound', title='Korrelation von Datum und compound')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading