jacobwilliams / pyplot-fortran Goto Github PK
View Code? Open in Web Editor NEWFor generating plots from Fortran using Python's matplotlib.pyplot π
License: Other
For generating plots from Fortran using Python's matplotlib.pyplot π
License: Other
Dear Jacob:
Is it possible to add support for wireframe style of plot? After some testing I think to add functionality of wireframe to pyplot-fortran, we only need to change this line:
CS = ax.plot_wireframe (X,Y,Z,label="muw",antialiased=False,linestyles="-",linewidths=1)
from plot_surface
to plot_wireframe
.
Add tight_layout support.
Hi Jacob,
I am using your great pyplot-fortran into WenOOF... it is half an hour and I am already addicted to it... great!
I have a request. Can you transform the docstring into ford-compliant syntax in order to produce well documented API? Or do you accept PR? In case, I can fork pyplot-fortran and submitting PR.
As you can see here pytplot-fortran API doc is missing.
This warning is shown while the program test.f90
is running:
orbit.py:16: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
ax = fig.gca(projection='3d')
add option for ax.ticklabel_format(useOffset=False)
Hello!
Thanks for the great project!
I tried to build (compiles) and run tests. I got an error:
β pyplot-fortran git:(master) fpm build --profile release
pyplot_module.F90 done.
libpyplot-fortran.a done.
[100%] Project compiled successfully.
β pyplot-fortran git:(master) fpm test
pyplot_module.F90 done.
libpyplot-fortran.a done.
test.f90 done.
color_test.f90 done.
test done.
color_test done.
[100%] Project compiled successfully.
Traceback (most recent call last):
File "/home/eelis/git/pyplot-fortran/test/errorbar.py", line 22, in <module>
ax.errorbar(x,y,fmt=".",linewidth=3,markersize=3,label="y",xerr=xerr,yerr=yerr)
File "/home/eelis/miniconda3/envs/kqcircuits/lib/python3.11/site-packages/matplotlib/__init__.py", line 1465, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/eelis/miniconda3/envs/kqcircuits/lib/python3.11/site-packages/matplotlib/axes/_axes.py", line 3674, in error
bar
raise ValueError(
ValueError: 'xerr' must not contain negative values
so the library will work for single, double, or quad precision codes.
I'd vote for the module checking the command line starting with python3
if python
fails. More and more recent OSes install only python3.x and do not provide python
command at all.
Add a function to plot a sphere.
Need to remove this fixed tmp_file
name from the code. It should generate an unused file name as needed.
pyplot-fortran works great on Raspberry Pi (Debian Linux "Stretch" Raspbian Nov 2017).
Python 2 is the default on the Pi, but ford fails under python 2. (annoying but not fatal).
To use with python3 the following software must first be installed:
$sudo apt-get install gfortran graphviz python3-matplotlib
$sudo pip3 install FoBiS.py ford
Download pyplot-fortran and extract to a folder of choice.
Edit pyplot_module.f90 using Geany IDE (installed). Modify lines 25 and 189 to
change 'python' to 'python3'.
Run the build.sh script. The module is created and may be used in fortran programs.
Now run the test program in /bin. Voila'! Check out the .png files and .py files .
TipOHat: The .py files can be modified and re-run! (make executable first).
Nice work Jacob. Thank you.
The present status is already useful in many situations, but it would be very appreciated a greater support for most of the matplotlib features.
Have you planned a road-map to extend the library?
Can I contribute? Do you accept PR? I can fork and try to add other matplotlib interfaces.
Running the program test gives
Error: Missing actual argument for argument βistatβ
probably seems that istat argument is after some optional arguments leading to trouble
Python provides a C API, that lets you call python directly, I was wondering if you ever looked into this rather than using system calls to write out then execute python scripts.
Just starting to get into matplotlib myself, and was wondering if that might be an easier route for the end user... maybe not.
I suggest adding the topics plot
, plotting
in the About section so that searches like language:fortran topic:plotting
display your project.
del
Hi Jacob,
using your great library I see that the python script used to generate the plots figure (and generated itself from pyplot-fortran) is persistent even if you do not specify a name for it into the savefig method. My expectation was that if I do not specify the name of the python script that file was not persistent, on the contrary if you do not specify the name the script file is simply named with a temporary name.
This is a design feature?
I like to avoid a default persistent script. Maybe a simple solution could to be use the close(...STATUS='delete)
instead of close(...)
into the execute method.
Thank you for this incredibly useful project!
When labels or titles are defined that contain escape sequences, Python/matplotlib does not render the TeX strings correctly, e.g.:
call plt%initialize(..., ylabel='$\frac{\bar{x}}{\bar{x}_0}$', title='normalised $\bar{x}$ values', ...)
...
call plt%add_plot(..., label='$\bar{x}_0 \neq 0$', ...)
This is because e.g. the \b
, \f
and \n
are interpreted by Python as escape sequences for ASCII Backspace, ASCII Formfeed and ASCII Linefeed, respectively. At least, that is the case for me with Python 3.6, running on Ubuntu 18.04 via Windows Subsystem for Linux (WSL).
If the labels/titles are defined as raw string literals in Python notation, e.g. r"$\bar{x}_0 \neq 0$"
, this problem is avoided. This can be done by changing lines 261 - 264 in the initialize
subroutine:
if (present(xlabel)) call me%add_str('ax.set_xlabel(r"'//trim(xlabel)//'")')
if (present(ylabel)) call me%add_str('ax.set_ylabel(r"'//trim(ylabel)//'")')
if (present(zlabel)) call me%add_str('ax.set_zlabel(r"'//trim(zlabel)//'")')
if (present(title)) call me%add_str('ax.set_title(r"' //trim(title) //'")')
and everywhere label
is defined in add_***
subroutines for the different plot types (in lines 330, 411, 513, 603, 677 and 834):
'label=r"'//trim(label)//'")'
There may very well be reasons for not doing this, so I'm just wondering if this is a bug or a feature :-)
why did I make dpi
a string, rather than an integer?
double check that.
Eliminate the error stop
calls if there is a problem. Replace with a status code.
Hello,
I usually work with 2d data, mostly maps, and I thought you library would be nice to make some quick plots of my data instead of running the fortran code and then jump to python and make the same image.
Problem is my images are very big (3700x3700px) and your method of writing all pixels to the .py make it impossible for me to work.
I've implemented the method to call the imshow and for images of 1000x1000 it takes around +20s to run and produces a .py of +20MB, so it can be useful to someone if you want to add it to your code.
Anyway, this is a great job and is useful for more simple data.
Best regards,
Ricardo
subroutine add_imshow(me, x)
class(pyplot), intent (inout) :: me !! pyplot handler
real(wp),dimension(:,:),intent (in) :: x !! x values
character(len=:), allocatable :: xstr !! x values stringified
character(len=*), parameter :: xname = 'x' !! x variable name for script
if (allocated(me%str)) then
!convert the arrays to strings:
call matrix_to_string(x, me%real_fmt, xstr, me%use_numpy)
!write the arrays:
call me%add_str(trim(xname)//' = '//xstr)
call me%add_str('')
!write the plot statement:
call me%add_str('ax.imshow ('//&
trim(xname)//')')
call me%add_str('')
else
error stop 'Error in add_imshow: pyplot class not properly initialized.'
end if
end subroutine add_imshow
Hi Jacob,
If I compile pyplot-fortran with a paranoiac debug mode I obtain some warnings like
src/tests/pyplot_module.f90(235): warning #6477: Fortran 2008 does not allow this statement or directive.
error stop 'Error in add_plot: pyplot class not properly initialized.'
-------------------^
Hi Jacob:
Is it possible to use pyplot-fortran to plot the meshgrid of xgrid and ygrid on the z(:, :) rather than just only able to plot an z(:) in the 3d space?
Thank you!
HJ
So far I've had a great time with this package, as much as it becoming the main plotting backend of my new project HoneyTools. Now I wanted to switch away from the default matplotlib colors, so to have a plotting-style that is coherent with the logo and the general look of the project, but I encounter some tricky problems in doing that.
I define these two colors:
real(8), parameter :: F(3) = [0.4510d0, 0.3098d0, 0.5882d0] ! Fortran-lang color
real(8), parameter :: Y(3) = [0.9608d0, 0.8157d0, 0.0118d0] ! HoneyTools' Yellow
And call add_plot
as
! Sublattice "A"
call plt%add_plot(Ax,Ay,label='',linestyle='o',markersize=5,color=F)
! Sublattice "B"
call plt%add_plot(Bx,By,label='',linestyle='o',markersize=5,color=Y)
But I get the following runtime errors:
Traceback (most recent call last):
File "/Users/gbellomia/Dropbox/SISSA/QcmPlab/HoneyTools/xy_plot.py", line 1648, in <module>
ax.plot(x,y,"o",linewidth=3,markersize=5,label="",color=(0.49999999999999928,-1.0000000000000000,7.7942286340599480))
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 1635, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 312, in __call__
yield from self._plot_args(this, kwargs)
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 538, in _plot_args
return [l[0] for l in result]
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 538, in <listcomp>
return [l[0] for l in result]
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 531, in <genexpr>
result = (make_artist(x[:, j % ncx], y[:, j % ncy], kw,
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 351, in _makeline
seg = mlines.Line2D(x, y, **kw)
File "/usr/local/lib/python3.10/site-packages/matplotlib/lines.py", line 370, in __init__
self.set_color(color)
File "/usr/local/lib/python3.10/site-packages/matplotlib/lines.py", line 1030, in set_color
mcolors._check_color_like(color=color)
File "/usr/local/lib/python3.10/site-packages/matplotlib/colors.py", line 130, in _check_color_like
raise ValueError(f"{v!r} is not a valid value for {k}")
ValueError: (0.4999999999999993, -1.0, 7.794228634059948) is not a valid value for color
Traceback (most recent call last):
File "/Users/gbellomia/Dropbox/SISSA/QcmPlab/HoneyTools/xy_plot.py", line 2248, in <module>
ax.plot(x,y,"o",linewidth=3,markersize=5,label="",color=(0.49999999999999928,-1.0000000000000000,9.5262794416288248))
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 1635, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 312, in __call__
yield from self._plot_args(this, kwargs)
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 538, in _plot_args
return [l[0] for l in result]
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 538, in <listcomp>
return [l[0] for l in result]
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 531, in <genexpr>
result = (make_artist(x[:, j % ncx], y[:, j % ncy], kw,
File "/usr/local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 351, in _makeline
seg = mlines.Line2D(x, y, **kw)
File "/usr/local/lib/python3.10/site-packages/matplotlib/lines.py", line 370, in __init__
self.set_color(color)
File "/usr/local/lib/python3.10/site-packages/matplotlib/lines.py", line 1030, in set_color
mcolors._check_color_like(color=color)
File "/usr/local/lib/python3.10/site-packages/matplotlib/colors.py", line 130, in _check_color_like
raise ValueError(f"{v!r} is not a valid value for {k}")
ValueError: (0.4999999999999993, -1.0, 9.526279441628825) is not a valid value for color
Which imo highlight a clear problem in real array to string conversion, as requested here:
pyplot-fortran/src/pyplot_module.F90
Lines 375 to 380 in da68b01
An additional peculiar thing that I found is that the reported python runtime behavior happens if the -Wall
flag is passed to fpm. Without it I get an obscure fortran runtime error:
At line 377 of file build/dependencies/pyplot-fortran/src/pyplot_module.F90
Fortran runtime error: Index '3' of dimension 1 of array 'color' outside of expected range (2:1)
How is the expected range (2:1) if I pass a dimension(3) array? Why does -Wall
make me bypass the problem in Fortran (?! this really surprises me...) and get to the python exception? All this is quite strange to me and I have no idea of what could be happening, so I report it here, for documentation purposes.
Note: I saw that the
color=[a,b,c]
option inadd_plot
is currently not included in the CI test-suite. So this may be a long living problem here.
I'd love to use your wonderful project, but unfortunately there is a blocking issue for me.
The current Python code uses matplotlib's GUI, which does not work for me. I have no graphical support, so Python gives me a RuntimeError: could not open display
. This can easily happen working with remote servers, which I think is common for Fortran programmers.
The solution is to use matplotlib's OO API. So initialize a figure with matplotlib.figure.Figure
, which, unlike matplotlib.pyplot.figure
, does not try to open a window. The OO interface is also generally considered better style, and I imagine it might be faster.
This is addressed by pull request #22 .
Add RGB input option for specifying line colors.
If you run the test with n say 20000
Then the program goes crazy because it seems the Fortran cannot handle such big data in allocatable string!
I propose to not write x,y data (numeric data) into str!
Jacob, have you tried to compile in Visual Studio 2019? I was wondering if there were any flags that need to be disabled to make it compile. Tried it an had some issues:
Severity Code Description Project File Line Suppression State
Error Compilation Aborted (code 1) C:\Users\don.dotson\source\repos\matplotlib\module.f90 1
Error error #6251: This symbol has multiple PUBLIC statement/attribute declarations which is not allowed. [PYPLOT_WP] C:\Users\don.dotson\source\repos\matplotlib\module.f90 36
Error error #6418: This name has already been assigned a data type. [PYPLOT_WP] C:\Users\don.dotson\source\repos\matplotlib\module.f90 36
Error error #6251: This symbol has multiple PUBLIC statement/attribute declarations which is not allowed. [PYPLOT_WP] C:\Users\don.dotson\source\repos\matplotlib\module.f90 38
Error error #6251: This symbol has multiple PUBLIC statement/attribute declarations which is not allowed. [PYPLOT_WP] C:\Users\don.dotson\source\repos\matplotlib\module.f90 40
Error Compilation Aborted (code 1) C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 1
Error error #7002: Error in opening the compiled module file. Check INCLUDE paths. [PYPLOT_MODULE] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 4
Error error #6457: This derived type name has not been declared. [PYPLOT] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 9
Error error #6404: This name does not have a type, and must have an explicit type. [PLT] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 17
Error error #6460: This is not a component name that is defined in the encompassing structure. [INITIALIZE] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 17
Error error #6460: This is not a component name that is defined in the encompassing structure. [ADD_PLOT] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 19
Error error #6460: This is not a component name that is defined in the encompassing structure. [SAVEFIG] C:\Users\don.dotson\source\repos\matplotlib\Source1.f90 20
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.