-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support non-Float64 number types #77
Comments
It appeared to me that you have probably no idea what I'm talking about and I actually made a mistake in my analysis, so let me try to explain what I did. I wanted to plot the following: Now, another issue that came up in the course of testing this is that for small values the y axis is a little messed up: If I multiply by 10^9 this is what it looks like: Sorry for being so unprecise in the original issue @dcjones. I was in a bit of a hurry trying to get the thing the graphs were for written up. |
Ok, I see what you're getting at, thanks for clarifying. It doesn't recognize your custom number type as a number and treats it as categorical data, hence the messed of axis. Would it be sufficient to support custom numbers types by converting them to Float64 internally, or are you looking for something more sophisticated? The rounding of small numbers to zero is clearly a bug. Should be easy to fix though. |
I would prefer not to convert everything to Float64, since I would like the axis labels to include untits (i.e. displaying Units). Would it be possible to have some sort of |
Now that I think of it, converting to Float64 is also a dead end if I want to be able to correctly plot e.g. BigFloat numbers. It will take some work to make the change the right way, but I'll see what I can do. |
Good point. |
I've just pushed a bunch of changes to Compose and Gadfly that should make this possible. It should allow plotting any type as a number as long as a handful of functions are defined for that type. Here's the example I was playing with. using Gadfly
import Base: show, +, -, /, *, isless, one, zero, isfinite
# A type I'd like to be able to plot
immutable Percent
value::Float64
end
# Functions necessary for plotting
+(a::Percent, b::Percent) = Percent(a.value + b.value)
-(a::Percent, b::Percent) = Percent(a.value - b.value)
-(a::Percent) = Percent(-a.value)
*(a::Percent, b::Float64) = Percent(a.value * b)
*(a::Float64, b::Percent) = Percent(a * b.value)
# Must return something that can be converted to Float64 with float64(a/b)
/(a::Percent, b::Percent) = a.value / b.value
isless(a::Percent, b::Percent) = isless(a.value, b.value)
one(::Type{Percent}) = Percent(0.01)
zero(::Type{Percent}) = Percent(0.0)
isfinite(a::Percent) = isfinite(a.value)
show(io::IO, p::Percent) = print(io, round(p.value, 4), "%")
y=[Percent(0.1), Percent(0.2), Percent(0.3)]
plot(x=collect(1:length(y)), y=y) Let me know if this works for what you were trying to do, or needs some tweaking. |
Sorry for now getting back to you on this earlier. This works great now. Here's a fun example: The "just works" on that one was pretty great! |
Also while we're on the above plot example, is there any way to specify that more concisely (e.g. |
For regular floating point numbers, there is a function (in format.jl) that tries to print numbers uniformly and at a reasonable precision. I'm not sure how to extend that to other types though, so they just get "string" called on them. The only solution now is to import
Not really. I was thinking of introducing something like that, but probably with tuples to avoid ambiguity with plotting arrays directly.
That's basically how you have to do it now. I'm seeing the need to make that more convenient. I could imagine this being written like: plot(datadm,
x="in",
y=("vol1", "vol2", "in", "in2"),
color=(["A"], ["B"], ["C"], ["D"])
Geom.line) Then letting |
I was going to say that transforming the data frame to be suitable for |
I think the main thing that was remaining here was making formating non-float types easier. I've forked that into a new issue (#329) and am closing this one. |
It seems to me that sometimes Gadfly automatically scales the plot (e.g. loglog or something like that), but the y-axis label still says
f(x)
. When such an automatic transformation is applied and default labels are used, that should be fixed automatically.Relatedly, scale transforms currently expect the number to have a conversion to Float64. It would be nice to get rid of that as the rest of Gadfly is already blissfully ignorant to units, allowing things like
using my SIUnits package. However, this doesn't work if a scale transform (even the identity transform) is being applied.
EDIT: Title updated to reflect real issue (see below).
The text was updated successfully, but these errors were encountered: