10
votes
Modifying Titration Data analysis results
I've never used numpy or matplotlib, so I can only speak to issues of style.
You're allowing for far too much nesting here. Your code consists of a giant, dense, deeply nested chunk. As a result, the ...
9
votes
Accepted
Farthest point algorithm in Python
First, a style comment. On the internet, especially in programming, and in particular on this website, English is the lingua franca. So you should avoid mixing other languages and English. This way ...
9
votes
Accepted
Python Sound visualizer
Nice.
Here are some observations:
consider using an IntEnum:
This helps remove "magic" numbers from the source code. (A year from now, will you remember that <...
8
votes
Accepted
A Python script to plot data and save to PDF
coding style
Your code is almost pep-8 compliant. There are a few spaces missing after comma's, but all in all this is not too bad. I myself use black to take care of this formatting for me.
some of ...
8
votes
Modifying Titration Data analysis results
I'm going to put this code into an editor, "proofread" it from top to bottom, give notes as I go, and then paste the final result to show the effect of the edits.
Code editors don't usually wrap lines ...
7
votes
Accepted
Calculating relay operating times, according to IEC 60255
You need not declare # -*- coding: utf-8 -*- in Python 3: UTF-8 is the default.
Writing I = np.logspace(…) inside your ...
7
votes
Accepted
Implementing a joint differential equation and eigenvalue solver
My primary goal here is to verify the correctness of my method and its implementation in code
You've done some things well - you have seemingly descriptive variable names and comments.
You need to ...
6
votes
Compute and plot a 2D vector field with radial symmetry in Python
Is there a suitable plotting function allowing to avoid to compute and store the two potentially large arrays u and v, and ...
6
votes
Accepted
Plotting Collatz conjecture values - Python
Note how you're manually repeating the number of seeds (1500):
colors = plt.cm.bwr(np.linspace(0, 1, 1500))
for i in range(1, 1500):
...
That's always a good ...
5
votes
Accepted
Probability of event using Central Limit Theorem + plotting results
You seem to know about str.format (since you use it), yet you are still doing string addition:
...
5
votes
Accepted
Pythonic way of managing data for plotting 2D variance plots
Your function proc can be greatly reduced by using the fact that numpy functions are vectorized and most of them take the axis ...
5
votes
Accepted
Image processing and plotting
Usually, when using for loops and numpy together, you’re probably doing it wrong.
Some things you could replace in your code:
Use ...
5
votes
Accepted
Measure size of repository as a function of time
This is good, useful, powerful. Let's make it better!
There's no need for os here, so remove it. os.curdir can just be ...
5
votes
Accepted
Modularizing matplolib graphing based on a data dictionary
The biggest challenge I had with understanding how your code works was around what panelize's and single_plot's ...
5
votes
Accepted
Python implementation of approximating the chance a particle is at a location after n steps in the cardinal directions
Your directions dictionary is only used by get_direction; why not put it inside the function rather than have it as a global? I'...
5
votes
Accepted
Predator-prey simulation
Shebang
#!/opt/anaconda3/bin/python
This is suspicious. Usually you should just
#!/usr/bin/env python
and make sure that ...
5
votes
Python Sound visualizer
In addition to what RootTwo already mentioned, I would also advise to:
Define all class attributes in __init__
When I want to understand a new class, the first ...
5
votes
Plotting shapely polygon in matplotlib
Unfortunately I don't know of a better way (but have also not looked into one, tbh). Here are some comments on your pathify method instead.
You are currently ...
5
votes
Accepted
groupby in pandas and plot
J_H's advice about DRY is good for Python in general.
However for Pandas in particular, we should almost never iterate. Instead we chain methods that operate on the calling object.
Here your repeated ...
4
votes
MCMC Metropolis Hastings for German Tank Puzzle
A lot needs to change for this to be an efficient Monte Carlo simulation.
All use of the uniform stats object should be removed. It's really slow, and that's ...
4
votes
Accepted
Live plot with many subplots
First notice that you're using essentially none of the features of matplotlib. There are no titles, axis labels or annotations of any kind. Your example assumes that ...
4
votes
Sum, validate, and plot monthly inventory levels
DataFrame.append has been deprecated and is no longer available, so your code does not run.
If you use a pathlib.Path and make ...
4
votes
Accepted
Calculating pi via collisions
I am currently using the RK-4 method to update position
Firstly, the naming is unhelpful here. A name like RK4_1 implies that the method does the quadrature. I ...
4
votes
Accepted
Matplotlib real-time monitor with reversed time
UX
The GUI looks great, and the message at the top of the graph is helpful.
However, exiting out of the GUI is a little awkward. When I click on
the "x", the GUI window closes, but I still ...
4
votes
Demonstrate the central limit theorem
Some suggestions:
Black will reformat this code to a recognizable and very readable layout.
Concatenating strings using + is not pythonic. The standard way to do ...
4
votes
Accepted
Optimizing Multiple Subplot Visualization and Navigation in Matplotlib
cached bitmaps
Consider asking matplotlib to save a .PNG copy of each displayed plot.
Then you can rapidly switch between them upon encountering a cache hit.
Consider employing the
streamlit
library, ...
4
votes
Plotting Collatz conjecture values - Python
Integer arithmetic
seed = seed/2 takes the value of seed (initially an integer) and divides it by 2, and stores the result as a <...
4
votes
Accepted
Collatz conjecture plots (python)
Since there is only 1 argument ... what I cannot understand is why it doesn't put collatz_values on the x axis.
That's just how matplotlib implemented it. If you ...
4
votes
Accepted
Slack User Interaction Graph – Collaboration Topology
There are many examples in the code where mutable structures should be made immutable. To your credit, most of the code workflow is already reasonable insofar as lack of mutation; you just need to ...
3
votes
Accepted
Regularised regression code
You can get rid of some of the repetition using a for loop looping over the lambdas and colors and using tuple assignment to at least get rid of one level of having ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
matplotlib × 179python × 177
numpy × 53
python-3.x × 33
pandas × 24
data-visualization × 20
performance × 17
beginner × 11
simulation × 11
tkinter × 10
statistics × 9
python-2.x × 8
animation × 7
graph × 6
scipy × 6
object-oriented × 5
histogram × 5
csv × 4
machine-learning × 4
numerical-methods × 4
collatz-sequence × 4
algorithm × 3
time-limit-exceeded × 3
image × 3
mathematics × 3