Posts

Showing posts with the label matplotlib

Flask stuck loading after opening a certain route with a function

Flask stuck loading after opening a certain route with a function I'm relatively new to Python and Flask. I've been trying to create a web application that reads data readings from a .txt file and plots them onto a matplotlib plot. In this web-app, I have a front page with 3 buttons. These buttons redirect to different routes with functions that read data and plot them onto a matplotlib plot. The web-app works perfectly only for the first time I go to either of these routes. After that nothing loads anymore. I guess I have an infinite loop of some sort but I can't figure it out. Also, after the website gets stuck the Python process starts consuming more resources. The problem persists only when I open this route on the web-app: @app.route("/temperature/") This loads without problems on the web-page, but only for one time and the whole web-app gets stuck and I cannot access any of the other routes either. Thanks in advance! EDIT 1 - Whole code below cloudapp.py (P...

Python matplotlib manipulating to use it in the plot title

Image
Python matplotlib manipulating to use it in the plot title assume I've the following variable roundi = theta_result_lasso.round(2) [ 0. -2.36] where theta_result_lasso.round are just two values. The line for my plot title is ax.set_title(r'Globales Minimum $hat beta$ = {}'.format(roundi), fontsize=20) producing this: is there a way to replace the "." after the zero by a "," and descreasing the disance between the two values as it should look like a "vector" ? It should look like this: [0, -2.36] If you Need further informations, I'll provide an example what is type(roundi) ? – jedwards Jul 1 at 22:16 type(roundi) class 'numpy.ndarray' – Leo96 Jul 1 at 22:18 ...

NameError: name 'Date' is not defined

NameError: name 'Date' is not defined I am trying the code below from the tutorial in youtube: https://www.youtube.com/watch?v=83-_3x2AjXI&t=3s I'm getting stuck on the following line plt.plot_date(date, closep,'-', label='Price') When running the script I'm getting the error message "NameError: name 'Date' is not defined" import matplotlib.pyplot as plt import numpy as np import urllib import matplotlib.dates as mdates #date converter/date processing def bytesdate2num(fmt, encoding='uftf-8'): strconverter = mdates.strdate2num(fmt) def bytesconverter(b): s = b.decode(encoding) return strconverter(s) return bytesconverter def graph_data(stock): stock_price_url = 'https://pythonprogramming.net/yahoo_finance_replacement' #dash dash plus stock plus dash dash source_code = urllib.request.urlopen(stock_price_url).read().decode() #add decode anytime python 'reads...

Python Matplotlib TickLabels

Image
Python Matplotlib TickLabels enter image description hereI am trying to round tick values in the plot, i am using this code ax.yaxis.set_major_formatter(FormatStrFormatter('%.2f')) However, the tick labels are converted to sequential values (fig1) when I use this, if I remove it goes back to correct values (fig2). Any suggestion why this is happening? I can see only one figure and I cannot see the code that produces it. – Goyo Jun 30 at 13:20 I uploaded the other picture. The idea is whenever i am trying to format the tick labels it just starts from 1 and plots the consecutive values with given intervals – Abat Jul 1 at 14:25 ...

Making ticks invisible pandas hist graph using pandas dataframe.hist api

Image
Making ticks invisible pandas hist graph using pandas dataframe.hist api I have tried everything using kwargs, set_visible, and other suggestions given in the docs but have not been able to make x_ticks disappear. Can you guys help me do this. One of the approaches suggested is following but it complains ax is numpy array and that has no affect is this fig, ax = plt.subplots(1, 1) ax.get_xaxis().set_visible(False) # Hide Ticks ns = dummy.hist(bins=20, ax=ax) This produces following - as you can see x ticks make the graph unreadable. Solved ns is of type ndarray, the shape of that is determined by the default layout: in my case it is (3,2). I had to call set_xticks on individual subplots as shown below rows, cols = ns.shape for r in range(rows): for c in range(cols): ns[r,c].set_xticks() This is related to matplotlib. Added tag. Possible duplicate of Remove xticks in a matplotlib plot? – Anton vBR Jul 1 at 13:...