- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Plot data from a .txt file using matplotlib
63 Lectures 6 hours
To plot data from .txt file using matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Initialize empty lists for bar_names and bar_heights.
- Open a sample .txt file in read "r" mode and append to bar's name and height list.
- Make a bar plot.
- To display the figure, use show() method.
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True bar_names =  bar_heights =  for line in open("test_data.txt", "r"): bar_name, bar_height = line.split() bar_names.append(bar_name) bar_heights.append(bar_height) plt.bar(bar_names, bar_heights) plt.show()
"test_data.txt" contains the following data −
Javed 12 Raju 14 Rishi 15 Kiran 10 Satish 17 Arun 23
It will produce the following output
- Plot data from CSV file with Matplotlib
- How to plot a very simple bar chart (Python, Matplotlib) using input *.txt file?
- How to make a txt file and read txt file from internal storage in android?
- How to plot a wav file using Matplotlib?
- How to store list in a txt file and read list from txt file in android?
- Make a multiline plot from .CSV file in matplotlib
- How can we import data from .txt file into MySQL table?
- How to extract data from a Matplotlib plot?
- How to extract all the .txt files from a zip file using Python?
- How to overwrite a line in a .txt file using Java?
- How to save an R data frame as txt file?
- How to plot a line graph from histogram data in Matplotlib?
- Read Data from a Text File using C++
- Reading UTF8 data from a file using Java
- How to make a 4D plot with Matplotlib using arbitrary data?