plot in Pandas immediately closes

2024/10/9 3:23:11

I have a problem of plotting the data. I run the following python code:

import pandas as pd
df = pd.read_csv("table.csv")values = df["blah"]
values.plot()
print 1df['blahblah'].plot()
print 2

My output is:

50728417:Desktop evgeniy$ python test2.py
1
2
50728417:Desktop evgeniy$ 

And finally I see how launches python icon( picture of rocket, by the way , what is it?) in my Dock( using mac os), and then it disappears. Printed numbers 1,2 show me that no error exist. So have no idea what to do next.

Answer

The problem is that pandas's DataFrame.plot does not block. Therefore the figures are closed when your program ends. Pandas uses matplotlib internally so you can circumvent this by calling matplotlib.pyplot.show with block=True like so:

import pandas as pd
import matplotlib.pyplot as pltdf = pd.read_csv("table.csv")values = df["blah"]
values.plot()
print 1df['blahblah'].plot()
print 2
plt.show(block=True)

This way the program will only end when plt.show returns, which is after you closed all figures.

https://en.xdnf.cn/q/70064.html

Related Q&A

Django template: Embed css from file

Im working on an email template, therefor I would like to embed a css file<head><style>{{ embed css/TEST.css content here }}</style> </head>instead of linking it<head><…

handling async streaming request in grpc python

I am trying to understand how to handle a grpc api with bidirectional streaming (using the Python API).Say I have the following simple server definition:syntax = "proto3"; package simple;serv…

Add new column to a HuggingFace dataset

In the dataset I have 5000000 rows, I would like to add a column called embeddings to my dataset. dataset = dataset.add_column(embeddings, embeddings) The variable embeddings is a numpy memmap array of…

Django: how to order_by on a related field of a related field

Im using annotate to add a property to an object which I can then use for order_by. However, I want to annotate on a field of a relation on a relation. I know I should be able to get to the field someh…

How to extract the cell state and hidden state from an RNN model in tensorflow?

I am new to TensorFlow and have difficulties understanding the RNN module. I am trying to extract hidden/cell states from an LSTM. For my code, I am using the implementation from https://github.com/ay…

Python - Nested List to Tab Delimited File?

I have a nested list comprising ~30,000 sub-lists, each with three entries, e.g.,nested_list = [[x, y, z], [a, b, c]].I wish to create a function in order to output this data construct into a tab delim…

How to make sure buildout doesnt use the already installed packages?

I am trying to switch fully to buildout - but our development environment already has lot of stuff installed in /usr/lib/pythonxx/How can I make sure that buildout doesnt use the libraries installed on…

Can python setup.py install use wheels?

I am using setuptools. Is there a way to have the following command use wheels instead of source?python setup.py installIn particular, I have a custom package that requires pandas. While pandas insta…

Getting the last element of a level in a multiindex

I have a dataframe in this format:a b x 1 1 31 1 2 1 1 3 42 1 4 423 1 5 42 1 6 3 1 7 44 1 8 65437 1 9 73 2 1 5656 2 2 7 2 3 5 2 4 5 2 5 34a a…

Sphinx and JavaScript Documentation Workflow [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 5…