swiftplot icon indicating copy to clipboard operation
swiftplot copied to clipboard

Default aesthetics of the plots

Open BradLarson opened this issue 4 years ago • 15 comments

Now that this is getting close enough to the point where people can start using it in notebooks, etc., I think it might help to improve some of the default aesthetics of the plots. The default settings for plots are producing graphs that aren't as aesthetically pleasing as other frameworks, but with a few slight tweaks to fonts, line size, spacing of numbers from the axis hatching, etc. I think the defaults could be made a lot nicer-looking.

For example, as a starting point, it would be nice if the following matplotlib plot:

https://matplotlib.org/gallery/lines_bars_and_markers/simple_plot.html#sphx-glr-gallery-lines-bars-and-markers-simple-plot-py

could be replicated using default settings for the framework, plus enabling a grid. Even that example isn't the greatest in terms of formatting, but people coming from matplotlib will expect something at least that readable.

We should find other examples of really nice-looking plots and see if they can be replicated in this framework with the right settings. That would give good targets for defaults on fonts, etc. at different plot sizes.

BradLarson avatar Jul 09 '19 21:07 BradLarson

I'll get to work on this next.

KarthikRIyer avatar Jul 13 '19 21:07 KarthikRIyer

@BradLarson @marcrasi to use a different font with AGG I will need to import truetype as a dependency. AGG has provisions to use different fonts using truetype. So, I tried importing this: https://github.com/PureSwift/CFreeType

but I am getting this error:

Fetching https://github.com/PureSwift/CFreeType.git
error: dependency graph is unresolvable; found these conflicting requirements:

Dependencies: 
    https://github.com/PureSwift/CFreeType.git @ 1.0.4

The repo has a 1.0.4 tag. Am I doing something wrong? Meanwhile I'll get to work on #29

KarthikRIyer avatar Jul 18 '19 14:07 KarthikRIyer

By adding FreeType as a dependency, will that require FreeType to be installed as a library before using the AGG renderer? Or is that commonly installed on systems and in environments like Colab?

What are you using in your Package.swift to pull in CFreeType? That error does sound odd, but I've hit that when I was trying to do an exact match and I got the release numbers slightly wrong.

BradLarson avatar Jul 18 '19 16:07 BradLarson

FreeType is commonly installed on Ubuntu atleast.

I think the release number isn't a problem, because I cloned the repo, deleted the git repository, initialized my own git repository, pushed my own tag, but still got the same error.

KarthikRIyer avatar Jul 18 '19 16:07 KarthikRIyer

Sorry, mean to ask: what is the exact code you're using in your Package.swift? I can try it on my end with a dummy project to see if I can figure out what's wrong.

BradLarson avatar Jul 18 '19 16:07 BradLarson

import PackageDescription

let package = Package(
    name: "SwiftPlot",
    products: [
       // Products define the executables and libraries produced by a package, and make them visible to other packages.
       .library(
       name: "SwiftPlot",
       targets: ["AGG", "lodepng", "CPPAGGRenderer", "CAGGRenderer", "SwiftPlot", "SVGRenderer", "AGGRenderer"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
         .package(url: "https://github.com/PureSwift/CFreeType.git", .exact("1.0.4")),
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
	.target(
            name: "AGG",
            dependencies: [],
    	      path: "framework/AGG"),
  .target(.....other targets

KarthikRIyer avatar Jul 18 '19 16:07 KarthikRIyer

Ah, I think the real problem might be due to CFreeType relying on Swift Package Manager 3.0.2 tooling. If I instead use

.package(url: "https://github.com/PureSwift/CFreeType.git", .branch("master")),

I get the following error:

https://github.com/PureSwift/CFreeType.git @ master: error: package at 'https://github.com/PureSwift/CFreeType.git' @ 079909dc68c13c700bb6bab3059ddf51f642b43a is using Swift tools version 3.0.2 which is no longer supported; use 4.0.0 or newer instead

You could try forking that and updating the CFreeType package's tools version on your end to see if that lets you import it.

BradLarson avatar Jul 18 '19 16:07 BradLarson

Ah, I think the real problem might be due to CFreeType relying on Swift Package Manager 3.0.2 tooling.

This was the problem. I am able to import it now.

KarthikRIyer avatar Jul 21 '19 13:07 KarthikRIyer

@BradLarson @marcrasi I'm trying to use the code from this branch in Jupyter. But I'm unable to use FreeType there:

 'CFreeType' /tmp/tmp7jj615q3/swift-install/package/.build/checkouts/CFreeType: error: configuration of package 'CFreeType' is invalid; the 'pkgConfig' property can only be used with a System Module Package
Install Error: swift-build returned nonzero exit code 1.

This is what I get. Also in the terminal I get this: 'CFreeType' /home/karthik/swiftplot/.build/checkouts/CFreeType: warning: system packages are deprecated; use system library targets instead I tried searching on the web. But nothing helped. Any ideas?

KarthikRIyer avatar Aug 06 '19 08:08 KarthikRIyer

It works when you do swift build / swift run, but you get that error when you try to use it through jupyter?

Is it possible that you're using different versions of the swift toolchain from the commandline and from jupyter? Try running these commands to see:

  • which swift
  • swift package --version
  • <path to toolchain used in jupyter>/usr/bin/swift package --version

Maybe changing it to use a system library target (like you have in the commented out code in your CFreeType Package.swift) will help. Do you also get problems if you try it with that?

marcrasi avatar Aug 12 '19 18:08 marcrasi

It works when you do swift build / swift run, but you get that error when you try to use it through jupyter?

Yes

I do not remember remember the path which I used with jupyter. (I've got two versions). But I am pretty sure I must be using the same one.

Using the system library targets gave errors when building on Mac. That's why I changed it.

KarthikRIyer avatar Aug 12 '19 19:08 KarthikRIyer

@marcrasi any ideas on how to get FreeType working in Jupyter?

KarthikRIyer avatar Aug 22 '19 19:08 KarthikRIyer

I'll try to run it myself today and see if I can figure anything out.

marcrasi avatar Aug 26 '19 15:08 marcrasi

Try adding this. I think it made it work for me: %install-swiftpm-flags -Xcc -isystem/usr/include/freetype2 -Xswiftc -lfreetype

marcrasi avatar Aug 27 '19 03:08 marcrasi

Thanks @marcrasi it builds now! But plotting in Jupyter isn't working. It still works with the old code. The one tagged 0.0.1 on GitHub. I'll try to look into it soon. I'm getting this error in the terminal https://pastebin.com/Ty00PWg8 Did you try out an example plot? Did it work for you?

KarthikRIyer avatar Aug 28 '19 15:08 KarthikRIyer